Difference between Java and Javascript on 1st Jan 0001 UTC -
i have difference of how date 1st jan 0001 utc represented in java , in javascript
in java:
timezone utctimezone = timezone.gettimezone("utc"); calendar cal = calendar.getinstance(utctimezone); cal.clear(); //1st jan 0001 cal.set(1, 0, 1); date date = cal.gettime(); system.out.println(date);//sat jan 01 00:00:00 gmt 1 system.out.println(date.gettime());// -62135769600000
in javascript:
var date = new date(); date.settime(-62135769600000); date.toutcstring(); //"sat, 30 dec 0 00:00:00 gmt"
why date, 1 jan 0001 utc, represented time -62135769600000l in java, not represented 1st of january when displayed in javascript?
it looks because gregoriancalendar
in java hybrid between gregorian calendar , julian calendar:
gregoriancalendar hybrid calendar supports both julian , gregorian calendar systems support of single discontinuity, corresponds default gregorian date when gregorian calendar instituted (october 15, 1582 in countries, later in others). cutover date may changed caller calling setgregorianchange().
if take 1500-01-01 example, java , javascript values 10 days apart.
to make pure gregoriancalendar
, can use this:
gregoriancalendar cal = new gregoriancalendar(timezone.gettimezone("utc")); cal.setgregorianchange(new date(long.min_value));
then value of -62135596800000 0001-01-01, gives same date javascript.
cutover calendars pain in neck - make kinds of things odd, , never useful. (i suspect use cases are appropriate may have different requirements, too. decided not implement noda time in end :)
Comments
Post a Comment