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

Udaykiran
  • 5,863
  • 9
  • 42
  • 75

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
  • 18,934
  • 19
  • 83
  • 124
1
SimpleDateFormat form = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss aa");

try this

Bojan Kogoj
  • 4,965
  • 2
  • 34
  • 56
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
  • 36,011
  • 11
  • 98
  • 132
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,811
  • 2
  • 20
  • 38
-1
SimpleDateFormat form = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss aa");
Mohammed Azharuddin Shaikh
  • 40,812
  • 14
  • 95
  • 115