Comment convertir JavaScript Date à Date en Java

Mots clés : javajavascriptdatejava

meilleur 4 Réponses Comment convertir JavaScript Date à Date en Java

vote vote

95

var d = new Date().getTime(); 
// 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); 
vote vote

84

DateFormat jsfmt = new SimpleDateFormat("EE MMM d y H:m:s 'GMT'Z (zz)"); 
vote vote

70

java: String jsDate="2013-3-22 10:13:00"; Date javaDate=new SimpleDateFormat("yy-MM-dd HH:mm:ss").parse(jsDate); System.out.println(javaDate); 
vote vote

60

  var d = new Date();   var n = d.toISOString();   console.log(n);
    String stringFromJavaScript = "2021-07-12T05:54:03.365Z";     Instant inst = Instant.parse(stringFromJavaScript);     System.out.println(inst); 
    LocalDate date = inst.atZone(ZoneId.systemDefault()).toLocalDate();     System.out.println(date); 
    Date oldfashionedDate = Date.from(inst);     System.out.println(oldfashionedDate); 

Questions similaires