Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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...

like image 209
blong Avatar asked Sep 19 '11 13:09

blong


1 Answers

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).

like image 117
nfechner Avatar answered Oct 17 '22 20:10

nfechner