Are leap seconds catered for by the GregorianCalendar class?
If not, does any 3rd party library cater for it?
In modern Java, use only the java.time classes that supplanted the terribly-flawed legacy date-time classes. Never use Calendar
, Date
, SimpleDateFormat
, etc.
The java.time framework defines its own time-scale, the Java Time-Scale. For the details, see the explanation in the Javadoc of Instant
.
The upshot is java.time ignores leap seconds. The java.time classes by default pretend that every day is exactly 24 hours long. This makes sense as the purpose of Leap Second is to slow down our clocks to keep in synch with our calendar.
Instant.now()
& ZonedDateTime.now(…)
. And for SQL JDBC database work, OffsetDateTime
.See also the Question, Duration with leap seconds.