vamsi
vamsi

Reputation: 143

Simple Date Format Parsing -getting incorrect result

Date dateShipped = new SimpleDateFormat( "yyyy-MM-dd HH:MM:SS.SSS" ).parse("2013-08-29 22:41:03.537");
SimpleDateFormat fmt =  new SimpleDateFormat("dd MMM yyyy",Locale.ENGLISH);
System.out.println(fmt.format(dateShipped));

this results 29 May 2016

Why is the result different?

Upvotes: 1

Views: 176

Answers (3)

newuser
newuser

Reputation: 8466

Date Pattern Letters

new SimpleDateFormat( "yyyy-MM-dd HH:mm:SS.SSS" )

instead of

new SimpleDateFormat( "yyyy-MM-dd HH:MM:SS.SSS" )

MM for Month and mm for Minutes

Upvotes: 7

Prateek
Prateek

Reputation: 12252

Change MM(uppercase) of minutes to mm (lowercase)

    Date dateShipped = new SimpleDateFormat( "yyyy-MM-dd HH:mm:SS.SSS" ).parse("2013-08-29 22:41:03.537");
    SimpleDateFormat fmt =  new SimpleDateFormat("dd MMM yyyy",Locale.ENGLISH);
    System.out.println(fmt.format(dateShipped));

Upvotes: 0

Woody
Woody

Reputation: 939

try changing your code as following

Date dateShipped = new SimpleDateFormat("yyyy-MM-dd HH:mm:SS.SSS").parse("2013-08-29 22:41:03.537");

Upvotes: 1

Related Questions