How to Convert JavaScript Date to Date in Java?

前端 未结 6 1281
暗喜
暗喜 2020-12-08 13:19

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:

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 14:02

    You can create a java.util.Date object from the 'time since epoch' value of the JS Date

    javascript

    var d = new Date().getTime();
    

    java

    // get value from client (ajax, form, etc), and construct in Date object
    
    long valueFromClient = ...
    
    Date date = new Date(valueFromClient);
    
    String formatted = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
    

提交回复
热议问题