如何使用Java将JavaScript日期转换为日期? [英] How to Convert JavaScript Date to Date in Java?
问题描述
JsDate
转换为 java.util.Date。
我搜索到但我找不到任何东西。你可以帮我解决这个问题吗? 编辑:我在gwt secreen上进行这种转换过程。我在屏幕上有datepicker,它给我JsDate值,当我使用它的getValue()方法。所以我想把这个值放在具有Date类型的对象的属性中。
ObjectName.setDate(PickerName.getValue());
我希望我的编辑会更加清晰。
Edit2:
这一行是我的问题的解决方案: p>
myObject.setDate(new Date((long)myPicker.getValue()。getTime()));
日期转换的最佳方式是使用时间(以毫秒为单位) , 世界标准时间。 JS Date对象和java.util.Date类都支持转换为毫秒( getTime()
),并从毫秒(使用构造函数)实例化。
I need to convert JsDate
to java.util.Date.
I searched but i couldn't find anything. So could you help me with this problem?
Edit: I do this convertion process on gwt secreen. I have datepicker on screen and it gives me JsDate value when i use it's getValue() method. So i'm suppose to put this value into property of an object which has Date type.
ObjectName.setDate(PickerName.getValue());
I hope my edit will be more clear.
Edit2:
This line is the solution of my problem:
myObject.setDate(new Date((long) myPicker.getValue().getTime()));
The best way of dates conversion is using time in milliseconds, UTC. Both JS Date object and java.util.Date class support conversion to milliseconds (getTime()
) and instantiating from milliseconds (using constructor).
这篇关于如何使用Java将JavaScript日期转换为日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!