GWT: working with JsDate and Java date

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

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

However, when I want to use this date in widgets, say 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 to achieve this? What is the best way to convert a JsDate object to a Java Date object and vice versa?

Thank you so much

+3
source share
2 answers

Jason code does not work for me, as it getDueDateNative().getTime()returns double, not long. Therefore, you must also specify a value:return new Date((long) getDueDateNative().getTime());

+4
source

GWT Date JsDate , . , Date JsDate s:

public final Date getDueDate() {
  return new Date(getDueDateNative().getTime());
}

private final static JsDate getDueDateNative() /*-{
  return this["dueDate"];
}-*/;
+3

Source: https://habr.com/ru/post/1792275/


All Articles