-1

I have a string in this format "20140210084957" I want to convert it to local format. Am almost there except month is not correct, instead of FEB below code is giving JAN, how to fix this.

 String dt = valuelist[time];
    SimpleDateFormat datetime1 = new SimpleDateFormat("yyyymmddhhmmss");
    Date formatted = null;
    try {
        formatted =datetime1.parse(dt);
        } catch (ParseException e) {
        e.printStackTrace();
        }
        dt=formatted.toLocaleString();
        //dt = formatted.toString();
        Log.d("DT Formatted", ""+dt);
        valuelist[time] =dt;

}
vinay Maneti
  • 1,447
  • 1
  • 23
  • 31
Rida Shahid
  • 386
  • 7
  • 22

4 Answers4

2

use capital M for month i.e

 SimpleDateFormat datetime1 = new SimpleDateFormat("yyyyMMddhhmmss")
Ranjit
  • 5,130
  • 3
  • 30
  • 66
2

Replace the line SimpleDateFormat datetime1 = new SimpleDateFormat("yyyymmddhhmmss"); with this line : SimpleDateFormat datetime1 = new SimpleDateFormat("yyyyMMddhhmmss");

The Heist
  • 1,444
  • 1
  • 16
  • 32
1

Problem into month format. That should be MM instead of mm.

Change it to MM

Like

SimpleDateFormat datetime1 = new SimpleDateFormat("yyyyMMddhhmmss"); // result for month is 01 or 02 or 03

And for Jan/ Feb/ Mar like output

yo should use MMM for month.

SimpleDateFormat datetime1 = new SimpleDateFormat("yyyyMMMddhhmmss"); // Result of month is Jan or Feb or Mar

Read more about Date and Time Patterns

Pankaj Kumar
  • 81,967
  • 29
  • 167
  • 186
0

Another thing to note: If you have written every pattern symbol in small letters and you don't print or parse AM/PM then the format symbol h is probably wrong since it indicates the 12-hour-clock which is worthless without AM/PM-marker. In this case you should also use big letter H instead, like M instead of m is right for months.

Meno Hochschild
  • 42,708
  • 7
  • 104
  • 126