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 ? :
Period oneMonth = Period.parse("P1M");
LocalDate jan = LocalDate.of(2016, 1, 1);
System.out.println(jan);
LocalDate feb = jan.plus(oneMonth);
System.out.println(feb);
LocalDate mar = feb.plus(oneMonth);
System.out.println(mar);
System.out.println(ChronoUnit.DAYS.between(jan, feb));
System.out.println(ChronoUnit.DAYS.between(feb, mar));
, 1 1 st 1 st - 1 31 (AKA 1 (P1M) 31 (P31D)) 1 1 st 1 st ( 1 = 29 , 2016 - ).
1 = 24 ? . , :
Period oneDay = Period.parse("P1D");
Duration twentyFourHours = Duration.parse("PT24H");
ZonedDateTime z = ZonedDateTime.of(2017, 10, 14, 10, 0, 0, 0, ZoneId.of("America/Sao_Paulo"));
System.out.println(z);
System.out.println(z.plus(oneDay));
System.out.println(z.plus(twentyFourHours));
-, 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 , / , ).
user7605325