I need to get real world date and time in Java. I use:
Date date = new Date();
But I’m not sure that it is not just system time. I don’t need to be dependent on PC local date and time.
If it is so, then is there any way to abstract from it? I mean I need correct time and date. If today is the 1st of May, 2012 and user changed (maybe there was a system error) it to the 1st of December 2000, it shouldn’t affect business logic. So is there any alternative to achieve this?
Dateonly represents an instant in time, in milliseconds since the Unix epoch of January 1st 1970 UTC (modulo leap seconds). It has no concept of a time zone in its data. However, if you use thetoStringmethod it will always convert that UTC instant to a local date/time using the system time zone. That confuses a lot of users, making them think thatDatecontains a time zone – it’s just an illusion.Likewise
Datedoesn’t have any concept of a calendar system (Gregorian, Julian etc) or a “format”. Basically it’s just along🙂