Date And Time In Java 8 Introduction - The Last Date In Java 6,7,8 Calendar is "Sun Aug 17 12:42:55 IST 292278994"

     Java 8 introduced a new, consistent, and well thought out package for date and time handling. Developers suffered for a decade and half under the inconsistencies and ambiguities of the Date class from Java 1.0 and its replacement, the Calendar class from Java 1.1 .

The key benefits of the new API are

1. It provides useful operations such as adding / subtracting dates / times.
2. All the objects are immutable, and thus thread safe.

All the new Date and Time classes developed in Java 8, represents time in either continuous or human time.

What Is Continuous Time ?

    continuous time is based on Unix time i.e the Unix time starts from “January 1, 1970 UTC - 00:00:00”, this is the time Unix was invented. In Unix time system, the unit of increment is one second of time. This has been used as a time base in most operating systems developed since. The time since 1970 is represented as 32 bit integer, and it runs out fairly soon - in the year 2038 AD. Most Unix systems now, are headed in advance and converting the time value from 32 bit quantity to a 64 bit quantity. Java8 also used this time base, but based its time in milliseconds, since a 64 bit time in milliseconds since 1970 will not overflow until “quite a few” years into the future i.e until August 17, 292,278,994 CE .

The Current Maximum Date is Mon Jan 26 02:01:23 IST 1970

package com.speakingcs.DateTime;

import java.util.Date;

public class EndTime {

 public static void main(String[] args) {    
  Date endOfTime = new Date(Integer.MAX_VALUE);  
  System.out.println("The current maximum date is " + endOfTime);
 }
}

The New Maximum Date is Sun Aug 17 12:42:55 IST 292278994 . This is 22 times greater than estimated age of Universe.

package com.speakingcs.DateTime;
import java.util.Date;

public class EndTime {
  public static void main(String[] args) {
    Date endOfTime = new Date(Long.MAX_VALUE);
    System.out.println("Java 8 time ends at " + endOfTime);
}
The output is Java 8 time ends at Sun Aug 17 12:42:55 IST 292278994 .

The new Date and Time package in Java 8 is biased towards "ISO 8601 " dates, In ISO 8601, the default format is for example 2015-10-23 T 10:22:45.


Comments