Given the following UTC time:
2009-11-17 10:45:32
How can I create an org.jode.time.LocalDateTime
with that exact time, but in UTC?
In other words, that time-stamp represents a UTC time. I'd like to make a new Timestamp object in joda
with that time in UTC.
I tried the following unsuccessfully:
scala> org.joda.time.LocalDateTime.parse("2009-11-17 10:45:32",
org.joda.time.format.ISODateTimeFormat.tTime)
java.lang.IllegalArgumentException: Invalid format: "2009-11-17 10:45:32"
I suspect the problem here is just the lack of a T
in the value. Note that the idea of "a LocalDateTime
[...] but in UTC" is meaningless. A LocalDateTime
value has no time zone.
The simplest fix is probably just to create a DateTimeFormatter
from a pattern:
// Java code, but Scala should be similar
DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime dateTime = format.parseLocalDateTime(value);
You can create the DateTimeFormatter
once and store it in a static final variable - DateTimeFormatter
is thread-safe (unlike SimpleDateFormat
, for example.)
See more on this question at Stackoverflow