简体   繁体   中英

Using Joda DateTime on the backend, how do I convert to a JavaScript Date object?

I'm using the Joda DateTime object (per SO recommendations) heavily on the Java back-end of my application. But I've not figured out a very consistent way to go back and forth to JavaScript. The Date object described by MDN seems to indicate that "IETF-compliant RFC 1123 timestamps" are a standard format, but my searches didn't seem to turn up a formatter built into the Joda library to get my DateTime object in that format.

Is there a simple method I can invoke to convert a DateTime object to a format consumable by my web-client? Will it support IE8 (in terms of JavaScript)?

* Note : I'm not using Spring or anything that does automatic binding (serialization/deserialization) and it's not an option at this point. I know, I know...

The easiest solution is to use the miliseconds since epoch version of the javascript Date constructor. For the conversion you can use DateTimeUtils.getInstantMillis(ReadableInstant instant) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM