I have this string I want to convert to a java Date object:
"Mon Jun 12 2017 21:00:15 GMT+0200 (W. Europe Summer Time)"
The first thing I do is splitting the string before the first '(' then removing any trailing spaces so I'm left with:
"Mon Jun 12 2017 21:00:15 GMT+0200"
Right now I'm trying to parse it using the following SimpleDateFormat pattern:
"E M d y H:m:s 'GMT'Z"
Unfortunately that won't work. I tried a few variations but nothing will work. Is it even possible to convert that particular string to a Date?
SimpleDateFormatandDateclasses? Any reason? I would suggestOffsetDateTime.parse("Mon Jun 12 2017 21:00:15 GMT+0200", DateTimeFormatter.ofPattern("EEE MMM d uuuu HH:mm:ss 'GMT'XX", Locale.ENGLISH)). The modern date and time classes are so much nicer to work with (the format pattern letters are more or less the same).GMT+0200with patternOOOO(capital letter O), but it doesn’t work. It seems to require a colon:GMT+02:00. This may be a bug in Java 8, and if so, it may be fixed in Java 9.Dateclass because I had the time and date in one object which made it easy to persist to a MySQL database using database type DATETIME. I used the SDF because that's all I come a cross when I searched for ways to convert string to a temporal object. What would be the modern classes to use in this situation?Instant, it corresponds to the oldfashionedDateclass. TheOffsetDateTimeclass used in my first comment has atoInstantmethod that does what the name says. Please search your documentation and the net for details.