-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,488
  • 1
  • 23
  • 30
Rida Shahid
  • 376
  • 6
  • 22

4 Answers4

2

use capital M for month i.e

 SimpleDateFormat datetime1 = new SimpleDateFormat("yyyyMMddhhmmss")
Ranjit
  • 4,985
  • 3
  • 29
  • 64
2

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

The Heist
  • 1,402
  • 1
  • 16
  • 31
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,071
  • 26
  • 167
  • 187
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
  • 40,702
  • 7
  • 93
  • 118