0

I've got the following date Mon Feb 11 15:40:48 UTC+0100 2019, is it possible to parse it into a Date object without modifying it? I've tried to parse it with the SimpleDateFormat class, but I couldn't figure out any working date-format.

  • 1
    Yes it's possible. But what do you mean by "without modifying it" ? First, a String is immutable in Java, so basicly you can't modify it. Secondly, why you d'ont want to use a String derived from the original (like a substring fro example) ? – vincrichaud Apr 17 '19 at 14:37
  • Why are you using `Date` instead of `OffsetDateTime` or something appropriate from the `java.time` package? – RealSkeptic Apr 17 '19 at 14:44
  • @vincrichaud i would like to avoid using regexp or substring, because the date-format in the data I get is not strictly defined, so I don't want to depend on a hardcoded string modification – Nagy Tamás Apr 17 '19 at 14:47
  • 2
    What do you mean by "it's not strictly defined" ? The string does not always has this format ? How do you expect to parse it if it does not respect a format ? Or it does but you did not explain it ? You say you don't want to depend on hardcoded String modification, but SimpleDateFormat expect an hardcoded pattern... – vincrichaud Apr 17 '19 at 14:57
  • 1
    By the way, you might educate the publisher of your data about [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601). – Basil Bourque Apr 17 '19 at 15:15
  • Possible duplicate of [Java string to date conversion](https://stackoverflow.com/questions/4216745/java-string-to-date-conversion) – Samuel Philipp Apr 22 '19 at 17:55

0 Answers0