Convert Javascript new Date to Java joda DateTime format Convert Javascript new Date to Java joda DateTime format json json

Convert Javascript new Date to Java joda DateTime format


A bit late perhaps, but:

I had a similar problem. We use org.joda.time.LocalDate in our backend and passing a new Date() from javascript to the backend resulted in a conversion error.We solved this by using new Date().valueOf() instead. This will get the milliseconds since 1 jan 1970 (read about it at MDNs JavaScript Date page).

After that you could just do org.joda.time.LocalDate.parse(passedInValue)


Objects cannot be "sent" in API calls. Objects are serialized(convert to string in this case) and deserialized(convert to appropriate object from string)

In this case:
- Serialization: Convert the Javascript Date object to appropriate format in a string before making the POST call
- Deserialize: Refer Converting a date string to a DateTime object using Joda Time library to convert the string into a DateTime object.


You can convert JavaScript new Date().toString(),and post the string value to the server, then you can use SimpleDateFormat to convert this value to any date format in java server.