I am working with groovy (gremlin to traverse a graph database to be exact). Unfortunately, because I am using gremlin, I cannot import new classes.
I have some date values that I wish to convert to a Unix timestamp. They are stored as UTC in the format: 2012-11-13 14:00:00:000
I am parsing it using this snippet (in groovy):
def newdate = new Date().parse("yyyy-M-d H:m:s:S", '2012-11-13 14:00:00:000')
The problem is that it does a timezone conversion, which results in:
Tue Nov 13 14:00:00 EST 2012
And if I then convert that to a timestamp using time()
, that gets converted to UTC, then the timestamp generated.
How do I get new Date()
to not do any timezone conversions when the date is first parsed (and just assume the date as UTC)?
new Date().parse("yyyy-M-d H:m:s:S" + " Z", '2012-11-13 14:00:00:000' + ' 0000')
comes to mind... – Uniaxialjava.text.ParseException: Unparseable date: "2012-11-13 14:00:00:000 0000"
– Biasdef newdate = new Date().parse("yyyy-M-d H:m:s:S Z", '2012-11-13 14:00:00:000' + ' UTC')
.#parse
is static btw, so unless Gremlin forces you to you shouldn't need to create an instance ofDate
to call it. – Amir' +0000'
, not' 0000'
| @jahroy, I thought the example I gave appended the timezone, don't you? :) – Uniaxial