0

Hi I am trying to parse a string to a date but it is throwing the exception java.text.ParseException: Unparseable date: "1409239380000" (at offset 13). Here is my code:

String text="1409239380000";
try{
        SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date1=dateFormat.parse(text);
    }catch(Exception e){
        Log.e("Error final:", e.toString());
   }
Celt
  • 2,469
  • 2
  • 26
  • 43

1 Answers1

3

No need to parse anything. You can just create a new Date:

String text = "1409239380000";
Date d = new Date(Long.valueOf(text));

If what you are trying to do is to format the date in the way you specify, use format():

String text = "1409239380000";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(dateFormat.format(new Date(Long.valueOf(text))));

This prints

2014-08-28 17:23:00
Keppil
  • 45,603
  • 8
  • 97
  • 119