How do I parse this date format in Java?

Jordan Bancino :

I am clearly missing something but I don't know what. I wrote this example program that replicates a problem I'm having:

import java.util.Date;
import java.text.SimpleDateFormat;

public class TestDate {
    public static void main(String... args) throws Exception {
        // The input date format
        SimpleDateFormat iF = new SimpleDateFormat("MMM dd YYYY HH:mm");
        // The output date format
        SimpleDateFormat oF = new SimpleDateFormat("YYYY-MM-dd'T'HH:mm:ssXXX");
        // Parse an input date and format it
        System.out.println(oF.format(iF.parse("Aug 26 2020 18:00")));
    }
}

When I run it, the output is this:

2020-12-29T18:00:00-05:00

The time and time zone are correct, but why is the date December 29 when I clearly input August 26?

Please refer to the SimpleDateFormat documentation and see if you can figure out what I am doing wrong. I've tried using L in place of M like the documentation suggests, but I get the same result.

xingbin :

Use yyyy instead YYYY:

public static void main(String... args) throws Exception {
    // The input date format
    SimpleDateFormat iF = new SimpleDateFormat("MMM dd yyyy HH:mm", Locale.US);
    // The output date format
    SimpleDateFormat oF = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");
    // Parse an input date and format it
    System.out.println(oF.format(iF.parse("Aug 26 2020 18:00")));
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I parse a nonstandard date format in Excel?

How do I parse date String into Date object in Java?

What is this data format and how can I parse that do Java model

How do you parse date in the format:

How do I parse a date field and generate a date in string format in NiFi

How do I convert String date to Date format date in dd-MM-yyyy format in java

How do I format this date

How can I parse a date (provided as a string) in the "ddMM" format and convert it to a Date Object in Java?

What datetime format is this and how do I parse it?

How do I get DateTime::Format::Strptime to parse the date/times of leap seconds?

how can I parse my date stored as a String to a different format in Java?

How do I parse a date string in Racket?

How do I parse a date in September

how do I pass a date in text format to DATE format with sql

How do I convert a factor into date format?

How do I change date format in fullcalendar?

How do I format a date within R?

How do I format a date in JavaScript?

How do I format a Microsoft JSON date?

How do I format this date time?

How do I format a date with Dart?

How do I convert date to format "ddmmyyyy"

How do I fix Date Format

How can I parse this date format into datetime? Python/Pandas

How do I parse UTC and format to local time with Clojure's clojure.java-time library?

How do I parse "/Date(1459934700000)/" into a JavaScript Date object?

How to parse date in format MonthName DD, YYYY in java

How can I format date by locale in Java?

How can I change the date format in Java?