Created
October 27, 2015 07:08
-
-
Save MizukiSonoko/83759864c7d43132596d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss ZZZ").parseDateTime(s) | |
String s = "2011-11-29 10:40:24 Etc/GMT"; | |
// split the input in a date and a timezone part | |
int lastSpaceIndex = s.lastIndexOf(' '); | |
String dateString = s.substring(0, lastSpaceIndex); | |
String timeZoneString = s.substring(lastSpaceIndex + 1); | |
// convert the timezone to an actual TimeZone object | |
// and feed that to the formatter | |
TimeZone zone = TimeZone.getTimeZone(timeZoneString); | |
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |
formatter.setTimeZone(zone); | |
// parse the timezoneless part | |
Date date = formatter.parse(dateString); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment