0

I have a timestamp value "20150616182115452" which is "yyyyMMddHHmmss ", and i wanted to format it to "dd/MM/yyyy hh:mm:ss" .

i have tried

        String lastLogon = db.getDataAt(0,"VG_QRSE006_L_LGN_TIMESTAMP") ; 
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
        Date date = simpleDateFormat.parse(lastLogon);
        System.out.println(simpleDateFormat.format(date));

however, i got Unparseable date: "20150616182115452"

mhasan
  • 3,703
  • 1
  • 18
  • 37
hiboss
  • 317
  • 6
  • 15
  • 2
    So you parsed a String that looks like `"20150616182115452"` with a formatter, that understands `"dd/MM/yyyy HH:mm:ss"`. What did you expect? Use a correct formatter. – Tunaki Oct 05 '16 at 08:25
  • 1
    Use another `SimpleDateFormat` with the correct pattern ( "yyyyMMddHHmmss ") to parse the lastLogon String . – Arnaud Oct 05 '16 at 08:25
  • You say that the format is "yyyyMMddHHmmss" but you're trying to parse it with format "dd/MM/yyyy HH:mm:ss". It's not surprising that it doesn't work in that case. Use the right format. But even then it wouldn't work because your timestamp value is 3 characters longer than your format string. You're probably missing something in the format. – Erwin Bolwidt Oct 05 '16 at 08:25
  • Looks to me like you'll need two separate `SimpleDateFormat` objects - one for parsing and one for formatting. I don't think it will work to just use the same one twice. – Dawood ibn Kareem Oct 05 '16 at 08:35

0 Answers0