The Answer by Jim Garrison is correct and should be accepted. You are apparently seeing a Daylight Saving Time cut-over for a time zone such as Asia/Tehran
.
java.time
You are using troublesome old date-time classes that are now legacy, supplanted by the java.time classes.
Specify a time zone using ZoneId
to get a ZonedDateTime
object.
ZoneId z = ZoneId.of( "Asia/Tehran" ) ; // Testing the Daylight Saving Time cut-over in Iran.
ZonedDateTime zdt1 = ZonedDateTime.of( 2017 , 9 , 21 , 23 , 59 , 0 , 0 , z ); // Set the moment to what might *appear* be the minute before midnight but is not, is actually an hour and a minute before midnight.
ZonedDateTime zdt2 = zdt1.plusMinutes( 1 ); // Adding a minute takes us to 11 PM again, but with a different offset-from-UTC, for a 25-hours long day.
Dump to console.
System.out.println( "zdt1: " + zdt1 );
System.out.println( "zdt2: " + zdt2 );
See this code run live at IdeOne.com.
zdt1: 2017-09-21T23:59+04:30[Asia/Tehran]
zdt2: 2017-09-21T23:00+03:30[Asia/Tehran]
Notice how adding a minute to roll-over midnight sent us back to 11 PM on the same date but with a different offset-from-UTC, 03:30
versus 04:30
. So the 21st of September 2017 in Iran ran 25 hours long.
About java.time
The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date
, Calendar
, & SimpleDateFormat
.
The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.
To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.
Where to obtain the java.time classes?
The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval
, YearWeek
, YearQuarter
, and more.