Best practice in `Date` exchange between Java and JavaScript, considering the DST -
i'm writing web application needs transfer date between java , javascript. firstly, used milliseconds exchange date, mentioned here: https://stackoverflow.com/a/1007854/4675827.
however, there problem when came across dst, named daylight saving time. millisecond value java , javascript different sometimes. when store date part of date, saved time as: "2015-10-15 00:00:00", when pass millisecond value javascripts, became "2015-10-14 23:00:00". thus, date part has 1-day difference.
i'm wondering what's best practice exchange date
data between java , javascript, or can turn off dst in java?
thanks in advance!
finally, i able disable dst changing timezone settings of jackson mapper, used serialize , deserialize json objects.
i changed gmt+8, beijing time. doesn't use dst @ all.
mapper.settimezone(timezone.gettimezone(zoneid.of("gmt+8")));
you don't provide criteria "best practice", robust way transfer dates , times using time value. unix uses seconds since 1970-01-01t00:00:00z , ecmascript uses milliseconds since same epoch, conversion simple.
if send time value in seconds or milliseconds, convert date on client system (converting time value milliseconds if required), equivalent date object can used display date , time in either utc or client system timezone (often mistaken "locale") automatically allow daylight saving if in force.
there many questions on answers, e.g. convert unix timestamp time in javascript
regarding date strings formatted per iso 8601 2015-10-15t12:03:16z, browsers not have built–in support parsing such strings. if provide parser (say write own or use small library) can reliably accommodated.
iso 8601 strings can handy more human comprehensible time values, isn't consideration if humans aren't expected comprehend data.
Comments
Post a Comment