Is there a name for the date / time format, for example "1h10m",

This is a common thing even outside the software for transmitting time or time intervals in truncated form. For example: 1h10mtranslates to "One hour and ten minutes."

This can be abstracted to a set of rules. For example: date interval is represented as a combination _h, _m(etc), where the symbols _represent non-negative integers or floats that are summed into a single object date range.

Mix days, hours, minutes are allowed. For example, it 0.5d1h60mwill be synonymous 14h.

Is there any standard that is similar somewhere?

+1
source share
2 answers

The standard for this is Duration defined by ISO 8601 . Note that Interval is a different concept (also defined by the same ISO), although both are closely related:

  • A Duration determines the amount of time (for example, “1 hour and 10 minutes” or “2 years, 3 months and 4 days”). But this does not tell you when it starts or ends ("1 hour and 10 minutes" regarding what?). It is just the amount of time in itself.
  • ( wikipedia) - " ". , , , 4 :
    • , 2007-03-01T13:00:00Z/2008-05-11T15:30:00Z
    • , 2007-03-01T13:00:00Z/P1Y2M10DT2H30M
    • , P1Y2M10DT2H30M/2008-05-11T15:30:00Z
    • , P1Y2M10DT2H30M,

1, 2 3 ( ). , 2 3 P1Y2M10DT2H30M ( 2 , 3 ).


, P[n]Y[n]M[n]DT[n]H[n]M[n]S, :

  • P - ( ), .
  • Y - , .
  • M - , .
  • W - , .
  • D - , .
  • T - , .
  • H - , .
  • M - , .
  • S - , .

, "1 10 " P1Y10M, "1 10 " PT1H10M ( , T 1 (P1M) 1 (PT1M), M ).


@MattJohnson, , , .

Java 8 ( , ). , API java.time 2 (Period Duration), ( ).

  • 1 ? :

    // one month period
    Period oneMonth = Period.parse("P1M");
    // January 1st
    LocalDate jan = LocalDate.of(2016, 1, 1);
    System.out.println(jan); // 2016-01-01
    // January 1st plus 1 month period = February 1st
    LocalDate feb = jan.plus(oneMonth);
    System.out.println(feb); // 2016-02-01
    // February 1st plus 1 month period = March 1st
    LocalDate mar = feb.plus(oneMonth);
    System.out.println(mar); // 2016-03-01
    
    // difference between Jan 1st and Feb 1st = 31 days
    System.out.println(ChronoUnit.DAYS.between(jan, feb)); // 31
    // difference between Feb 1st and Mar 1st = 29 days (2016 is leap year)
    System.out.println(ChronoUnit.DAYS.between(feb, mar)); // 29
    

, 1 1 st 1 st - 1 31 (AKA 1 (P1M) 31 (P31D)) 1 1 st 1 st ( 1 = ​​29 , 2016 - ).

  • 1 = 24 ? . , :

    // 1 day period
    Period oneDay = Period.parse("P1D");
    // 24 hours period
    Duration twentyFourHours = Duration.parse("PT24H");
    // in Sao Paulo, summer time starts at Oct 15, at midnight
    // getting a date one day before DST change, at 10:00 AM
    ZonedDateTime z = ZonedDateTime.of(2017, 10, 14, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"));
    System.out.println(z); // 2017-10-14T10:00-03:00[America/Sao_Paulo]
    
    // add 1 day - gets the same hour (10:00 AM)
    System.out.println(z.plus(oneDay)); // 2017-10-15T10:00-02:00[America/Sao_Paulo]
    
    // add 24 hours - gets 11:00 AM because of DST shift (at midnight, clocks moved forward 1 hour)
    System.out.println(z.plus(twentyFourHours)); // 2017-10-15T11:00-02:00[America/Sao_Paulo]
    

-, 15 th 2017, DST ( 1 ), :

  • 24 14 th 10:00, 15 th 11 AM
  • 1 , 15 th 10 AM

, 1 = 23 - , 1- (P1D) 23 (PT23H)

DST, : 1 , 1 25 .

, , ( , 1 24 , / , ).

+1

: http://momentjs.com/docs/#/durations/

moment.duration(100); // 100 milliseconds
moment.duration(60000).humanize(); // a minute

. , ISO8601:

moment.duration(1, 'd').toISOString() // "P1D"

, "P3Y6M4DT12H30M5S" " , , , , ". http://momentjs.com/docs/#/durations/as-iso-string/

0

All Articles