4

new LocalDateTime("1999-12-31T00:00:00Z");

When I try to create this datetime, I get:

Exception in thread "main" java.lang.IllegalArgumentException: Invalid format: "1999-12-31T00:00:00Z" is malformed at "Z"
    at org.joda.time.format.DateTimeParserBucket.doParseMillis(DateTimeParserBucket.java:187)
    at org.joda.time.format.DateTimeFormatter.parseMillis(DateTimeFormatter.java:780)
    at org.joda.time.convert.StringConverter.getPartialValues(StringConverter.java:87)
    at org.joda.time.LocalDateTime.<init>(LocalDateTime.java:414)
    at org.joda.time.LocalDateTime.<init>(LocalDateTime.java:358)

How can I then parse that date to LocalDateTime?

membersound
  • 81,582
  • 193
  • 585
  • 1,120
  • You may be confused about the purpose of LocalDateTime. If trying to represent a date-time value using "wall clock time" as seen by someone in a locality looking at their own clock and calendar, then generate a String representing the date-time value by using a [DateTimeFormatter](http://www.joda.org/joda-time/apidocs/org/joda/time/format/DateTimeFormatter.html). LocalDateTime is not meant for a particular locality but for the general idea of date+time. Example as "This year's Christmas starts at midnight on December 25, 2014" which is a different moment in Paris than Montréal and Auckland. – Basil Bourque Dec 09 '14 at 23:06
  • possible duplicate of [Convert Joda DateTime with timezone to DateTime without timezone?](http://stackoverflow.com/questions/27381626/convert-joda-datetime-with-timezone-to-datetime-without-timezone) – Basil Bourque Dec 09 '14 at 23:12

1 Answers1

7

How can I then parse that date to LocalDateTime?

You can't - LocalDateTime represents a date and time that does not have an associated timezone at all. If you have a timestamp that is anchored to a timezone (UTC in this case) then you should be using DateTime instead of LocalDateTime.

Ian Roberts
  • 120,891
  • 16
  • 170
  • 183