javacalendar

Are leap seconds catered for by Calendar?


Are leap seconds catered for by the GregorianCalendar class?

If not, does any 3rd party library cater for it?


Solution

  • java.time

    In modern Java, use only the java.time classes that supplanted the terribly-flawed legacy date-time classes. Never use Calendar, Date, SimpleDateFormat, etc.

    Generally best to ignore Leap Second

    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.

    See also the Question, Duration with leap seconds.