2018/Java 10
String value = "Sunday, September 29, 2013 7:59:58 AM PDT";
String format = "EEEE, MMMM dd, yyyy h:mm:ss a zzz";
DateTimeFormatter formatter = new DateTimeFormatterBuilder()
.parseCaseInsensitive()
.appendPattern(format)
.toFormatter(Locale.US);
ZonedDateTime zdt = ZonedDateTime.parse(value, formatter);
System.out.println(zdt);
System.out.println(zdt.format(formatter));
どのプリント
2013-09-29T07:59:58-07:00[America/Los_Angeles]
Sunday, September 29, 2013 7:59:58 AM PDT
元の答え
で指定されている要件を満たすために、予想される形式を変更する必要があります。SimpleDateFormat
String value = "Sunday, September 29, 2013 7:59:58 AM PDT";
String format = "EEEE, MMMM dd, yyyy h:mm:ss a zzz";
SimpleDateFormat sdf = new SimpleDateFormat(format);
try {
Date date = sdf.parse(value);
System.out.println(date);
System.out.println(sdf.format(date));
} catch (ParseException ex) {
ex.printStackTrace();
}
どの出力...
Mon Sep 30 00:59:58 EST 2013
Sunday, September 29, 2013 7:59:58 AM PDT