admin管理员组文章数量:1410737
I have an entity at my java backend which has a joda DateTime
field called createdAt.
I have a post API to update these values on the Database.
The post API accepts application/json values
.
I have an use case where in i need to make a Ajax POST request from my javascript file that updates the entity with the current date.
Now that i need to pass a DateTime value in the POST data, i face a problem in converting the javascript Date object
into joda DateTime
.
I have tried sending the javascript Date object but it responds as :
Also Note: I cannot perform any actions on the data i receive from javascript before sending it to the repository on the java side.
I have an entity at my java backend which has a joda DateTime
field called createdAt.
I have a post API to update these values on the Database.
The post API accepts application/json values
.
I have an use case where in i need to make a Ajax POST request from my javascript file that updates the entity with the current date.
Now that i need to pass a DateTime value in the POST data, i face a problem in converting the javascript Date object
into joda DateTime
.
I have tried sending the javascript Date object but it responds as :
Also Note: I cannot perform any actions on the data i receive from javascript before sending it to the repository on the java side.
Share Improve this question edited Jul 20, 2015 at 7:55 Kousick Shanmugam Nagaraj asked Nov 19, 2014 at 8:09 Kousick Shanmugam NagarajKousick Shanmugam Nagaraj 8562 gold badges9 silver badges26 bronze badges3 Answers
Reset to default 3A 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.
本文标签: Convert Javascript new Date to Java joda DateTime formatStack Overflow
版权声明:本文标题:Convert Javascript new Date to Java joda DateTime format - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744848052a2628330.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论