Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a new LocalDateTime containing ZERO timezone?

Tags:

java

jodatime

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?

like image 578
membersound Avatar asked Oct 21 '25 03:10

membersound


1 Answers

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.

like image 55
Ian Roberts Avatar answered Oct 24 '25 09:10

Ian Roberts



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!