0

I have date in April 10, 1922 format, I want to convert this date to yyyy-MM-dd'T'HH:mm:ss'Z' format, but first i want to convert this string into date.

I created a pattern for it, to convert this string to date.

private static String datePatternDOB = "MMMM d, yyyy";
dateConversionFormat = new SimpleDateFormat(datePatternDOB);

Then i parsed date.

dateConversionFormat.parse("April 10, 1922")

but got following exception.

Method threw 'java.text.ParseException' exception.

java.text.ParseException: Unparseable date: "April 15, 1932" at java.text.DateFormat.parse(DateFormat.java:358)

dev90
  • 7,187
  • 15
  • 80
  • 153
  • 1
    I recommend you don’t use `SimpleDateFormat` and `Date`. Those classes are poorly designed and long outdated (the former in particular notoriously troublesome). Instead use `LocalDate` and `DateTimeFormatter`, both from [java.time, the modern Java date and time API](https://docs.oracle.com/javase/tutorial/datetime/). – Ole V.V. Apr 14 '19 at 19:45
  • `LocalDate.parse("April 10, 1922", DateTimeFormatter.ofPattern("MMMM d, yyyy", Locale.ENGLISH)).atStartOfDay(ZoneOffset.UTC).toString()` yields `1922-04-10T00:00Z`. – Ole V.V. Apr 14 '19 at 19:50

0 Answers0