简体   繁体   English

在后端使用Joda DateTime,如何转换为JavaScript Date对象?

[英]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. 我在我的应用程序的Java后端上大量使用Joda DateTime对象(根据SO建议)。 But I've not figured out a very consistent way to go back and forth to JavaScript. 但是我还没有想出一种非常一致的方法来回往返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. 由MDN描述Date对象似乎表明“符合IETF的RFC 1123时间戳”是一种标准格式,但是我的搜索似乎并未找到内置在Joda库中的格式化程序来获取该格式的DateTime对象。

Is there a simple method I can invoke to convert a DateTime object to a format consumable by my web-client? 我可以调用一种简单的方法将DateTime对象转换为Web客户端可使用的格式吗? Will it support IE8 (in terms of JavaScript)? 它是否支持IE8(就JavaScript而言)?

* Note : I'm not using Spring or anything that does automatic binding (serialization/deserialization) and it's not an option at this point. * 注意 :我没有使用Spring或进行自动绑定(序列化/反序列化)的任何东西,目前还不能选择。 I know, I know... 我知道我知道...

The easiest solution is to use the miliseconds since epoch version of the javascript Date constructor. 最简单的解决方案是使用javascript Date构造函数的纪元版本以来毫秒数 For the conversion you can use DateTimeUtils.getInstantMillis(ReadableInstant instant) . 对于转换,您可以使用DateTimeUtils.getInstantMillis(ReadableInstant instant)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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