0

Am having problem in using simple date format for this: having date as

12/13/2011 12:00:00 AM

For that am using:

SimpleDateFormat form = new SimpleDateFormat("dd/MMMM/yyyy HH:mm:ss");

but throwing an exception while coversion saying:

java.text.ParseException: Unparseable date: 12/13/2011 12:00:00 AM

how to fix this?

Thanks

Uday
  • 5,933
  • 9
  • 44
  • 76

5 Answers5

4

You are using HH:mm:ss

However, according to the Android Dev Reference, HH is for 24 hour clock.

use h or K or k depending your requirements instead.

Don't forget the am/pm marker as well which is denoted by a

Ranhiru Jude Cooray
  • 19,542
  • 20
  • 83
  • 128
1
SimpleDateFormat form = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss aa");

try this

Bojan Kogoj
  • 5,321
  • 3
  • 35
  • 57
1

try

SimpleDateFormat form = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss aa");

instead of

SimpleDateFormat form = new SimpleDateFormat("dd/MMMM/yyyy HH:mm:ss");
Niranj Patel
  • 32,980
  • 10
  • 97
  • 133
0

Convert Date from dd/mm/yyyy to mm-dd-yyyy

if (date.matches("\\d{2}/\\d{2}/\\d{4}")) {
    SimpleDateFormat fromUser = new SimpleDateFormat("MM/dd/yyyy");
    SimpleDateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
    parsedDate = myFormat.format(fromUser.parse(date));
}
Towkir
  • 3,889
  • 2
  • 22
  • 41
-1
SimpleDateFormat form = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss aa");
Mohammed Azharuddin Shaikh
  • 41,633
  • 14
  • 96
  • 115