Converting a string date in Java like so:
val sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.getDefault)
sdf.setTimeZone(TimeZone.getDefault)
sdf.setLenient(false)
sdf.parse("1581-01-01T05:51:00Z").getTime
which produces: -12274711740000
In javascript taking that timestamp and converting back to a string date like so:
var now = moment.unix(-12274711740).utc().format('YYYY-MM-DD hh:mm:ss.SSS');
produces: "1581-01-11 01:51:00.000"
The date expected is "1581-01-01 01:51:00.000", 10 days off.
What is odd is if it is any year after 1581 the date will come out correct. And any year before 1582 will be some number of days off (it can vary).
What is causing this discrepancy?