Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Convert JavaScript Date to Date in Java?

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 conversion process on GWT screen. I have Datepicker on screen and it gives me JsDate value when I use it's getValue() method. So I'm supposed to put this value into the 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())); 
like image 802
angaraeski Avatar asked Jul 30 '12 13:07

angaraeski


People also ask

How can I change the Date format of a Date object in java?

String date_s = " 2011-01-18 00:00:00.0"; SimpleDateFormat dt = new SimpleDateFormat("yyyyy-mm-dd hh:mm:ss"); Date date = dt. parse(date_s); SimpleDateFormat dt1 = new SimpleDateFormat("yyyyy-mm-dd"); System. out. println(dt1.

Can I convert a String in to a Date in java?

We can convert String to Date in java using parse() method of DateFormat and SimpleDateFormat classes.


1 Answers

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).

like image 75
AlexR Avatar answered Sep 22 '22 03:09

AlexR