Roy Hinkley
Roy Hinkley

Reputation: 10641

convert a date string into long in Android

I have a date string: 02/28/2013 06:20:00 PM

I have a date formater: SimpleDateFormat dateFmt = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss a");

java.util.Date tempDate;

when I parse the string with the formater and extract the date

tempDate = dateFmt.parse(xpp.getText()); 

I get a date that is off by 12 hours: Thu, Feb 28, 2013 6:20 AM

What am i overlooking?

Upvotes: 2

Views: 2497

Answers (1)

Jason Sankey
Jason Sankey

Reputation: 2338

The javadocs for SimpleDateFormat say that HH is for the hour in 24-hour format (0-23). For AM/PM format (1-12) you should use hh.

Upvotes: 2

Related Questions