tags:

views:

60

answers:

1

I have a date that is:

2009-10-12T00:00:00

How would I convert this into UNIX Milliseconds, on the client side in GWT? Please give actual advice and not links, as a lot of the ways I have tried lead me to deprecated methods that point to non-Javascript convertible code.

As GWT converts all client side Java you have written into Javascript, it's making it very difficult for me to figure out how to do it.

+1  A: 

DateTimeFormat seems to be what you are looking for :)

Update:
Some sample code showing the usage of the DateTimeFormat class:

DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd'T'HH:mm:ss");
long unix = dtf.parse("2009-10-12T00:00:00").getTime();

Of course, you can do whatever else you want with the Date object that DateTimeFormat.parse returns.

Also, be sure to read the JRE Emulation Reference to see which parts of the JRE GWT emulates and which you should leave alone.

Igor Klimer
I found this before and couldn't get it to work. Apparently you need a `Date` object however most of the methods have been deprecated by `Calendar` methods - which of course don't work with GWT.
day_trader
I've updated the answer - hopefully that makes it clearer :) About the `Date` class - yeah, it's kinda PITA to use it because 99% of it's methods are deprecated so you either ignore the warnings about depreciation or go another route :/ It's a weird decision by the GWT team - to support `Date`, but not `Calendar`.
Igor Klimer
@igro: It's probably because JavaScript also has a Date object that works roughly the same as Java's Date object.
R. Bemrose