Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minimum date in Java

Tags:

java

date

What is the minimum date value in Java?

like image 997
user463745 Avatar asked Oct 01 '10 10:10

user463745


People also ask

What is the max date in Java?

For the Date/Time (TZ) data type, the maximum date is January 18, 2038.

How can I compare two dates in Java?

In Java, two dates can be compared using the compareTo() method of Comparable interface. This method returns '0' if both the dates are equal, it returns a value "greater than 0" if date1 is after date2 and it returns a value "less than 0" if date1 is before date2.

What is the format of new Date () Java?

Creating A Simple Date Format String pattern = "yyyy-MM-dd" ; SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern); The specified parameter “pattern” is the pattern used for formatting and parsing dates.

Is Date deprecated in Java?

Date has some serious design flows, from the day it was introduced. Many of its methods were deprecated since Java 1.1 and ported to (abstract) java.


1 Answers

Don't forget that Date constructor happily accepts negative values.

Date date = new Date(Long.MIN_VALUE); 

returns

Sun Dec 02 22:47:04 BDT 292269055

I guess that's about the time of Big Bang dinosaurs :)

EDIT

As martin clayton answered, you can use the Calendar class to check the era. This will output 0 which stands for BCE:

Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date(Long.MIN_VALUE)); System.out.println(calendar.get(Calendar.ERA)); 
like image 197
Denis Tulskiy Avatar answered Sep 17 '22 17:09

Denis Tulskiy