I'm now writing web application that needs to transfer Date between Java and JavaScript. Firstly, I used milliseconds to exchange Date, which is mentioned here: https://stackoverflow.com/a/1007854/4675827.
However, there is a problem when it came across the DST, named Daylight Saving Time. The millisecond value for Java and JavaScript is different sometimes. Especially when I only store the date part of Date, I saved the time as: "2015-10-15 00:00:00", but when I pass the millisecond value to JavaScripts, it became "2015-10-14 23:00:00". Thus, the date part has 1-day difference.
I'm wondering what's the best practice to exchange Date
data between Java and JavaScript, or can I turn off DST in Java?
Thanks in advance!
Finally, I was able to disable DST by changing timezone settings of Jackson mapper, which is used to serialize and deserialize json objects.
I changed to GMT+8, Beijing Time. It doesn't use DST at all.
mapper.setTimeZone(TimeZone.getTimeZone(ZoneId.of("GMT+8")));