Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT: working with JsDate and Java Date

In my overlays I wrap a JavaScript Date object in a JsDate:

public final native JsDate getDueDate() /*-{
    return this["dueDate"];
}-*/;

However when I want to use that date in a widget, say a DateBox, I need to set the value as a Java Date. I could create a Java Date from my JsDate but I believe that adds some overhead.

Date javaDate = new Date(jsDate.getTime());

Is there a cleaner way of achieving this? What is the best way to convert a JsDate object to a Java Date object and vice-versa?

Thanks a lot

like image 531
Javier Ferrero Avatar asked Sep 11 '26 23:09

Javier Ferrero


1 Answers

Jason's code doesn't work for me since getDueDateNative().getTime() returns a double and not a long. Therefore you have also to cast the value: return new Date((long) getDueDateNative().getTime());

like image 79
Dennis Avatar answered Sep 14 '26 11:09

Dennis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!