I was expecting this to print 1970-01-01-00:00:00, but it prints 1970-12-31-19:00:00
What am I misinterpreting about how Date is counted from? It is one year off. I am running this on Windows 7 with JDK 1.6
System.out.println(new SimpleDateFormat("YYYY-MM-dd-HH:mm:ss").format(new Date(0)));
The equals() method of Java Date class checks if two Dates are equal, based on millisecond difference. Parameters: The function accepts a single parameter obj which specifies the object to be compared with. Return Value: The function gives 2 return values specified below: true if the objects are equal.
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); formatter. setLenient(false); try { Date date= formatter. parse("02/03/2010"); } catch (ParseException e) { //If input date is in different format or invalid. }
An initial date can be set via the constructor or by calling setValue(LocalDate) . The default value is null.
What am I misinterpreting about how Date is counted from?
new Date(0)
is January 1, 1970 in UTC. Your timezone is not UTC.
It is one year off.
No, it's not. The printed value is only 5 hours behind. Let me guess - you're somewhere in the eastern part of the US?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With