I have a date with this format: Sun Oct 19 01:00:00 ADT 2014
and I need to convert it to the following format but I cannot,
Here is my code:
// The test string
String str = "Sun Oct 19 01:00:00 ADT 2014";
// Formatter for the input date
final DateTimeFormatter inputFormat =
DateTimeFormatter.ofPattern("EEE MMM dd HH:mm:ss zzz yyyy");
// The parsed date
final LocalDateTime parsed = LocalDateTime.parse(str, inputFormat);
// The output format(s). Specify the one you need
final DateTimeFormatter outputFormat1 = DateTimeFormatter.ofPattern("yyyy/MM/dd");
final DateTimeFormatter outputFormat2 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
// Print
System.out.println(outputFormat1.format(parsed)); // -> 2014/10/21
System.out.println(outputFormat2.format(parsed)); // -> 2014-10-21
But it is not working at all and I am stuck with this from morning and really do not know how to solve it, Does anyone have any idea?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…