Last active
May 20, 2017 14:26
-
-
Save bhabanism/470e03db54981ad6ddedbba316dcaa9a 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
import java.text.DateFormat; | |
import java.text.ParseException; | |
import java.text.SimpleDateFormat; | |
import java.time.ZonedDateTime; | |
import java.time.format.DateTimeFormatter; | |
import java.util.Date; | |
public class DateDoubt { | |
public static final String DATE_FORMAT = "EEE MMM dd yyyy hh:mm:ss 'GMT'Z '('zzzz')'"; | |
public static void main(String[] args) throws ParseException { | |
String sDate = "Thu May 25 2017 10:00:00 GMT+1200 (New Zealand Standard Time)"; | |
parseDate(sDate); | |
} | |
private static void parseDate(String sDate) throws ParseException { | |
// works | |
DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT); | |
Date oldDate = dateFormat.parse(sDate); | |
System.out.println(oldDate.toString()); | |
//FIXME: can't parse?! | |
ZonedDateTime newDate = ZonedDateTime.parse(sDate, DateTimeFormatter.ofPattern(DATE_FORMAT)); | |
System.out.println("New Date : " + newDate.format(DateTimeFormatter.ofPattern(DATE_FORMAT))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment