4

Possible Duplicate:
how to convert milliseconds to date format in android?

I have a Milliseconds String and want to convert it to a Date String.

Like this:

Milliseconds: 1345032624325E12 -> Date: Wed Aug 15 2012 14:10:24

How can i do this?

Community
  • 1
  • 1
JohnD
  • 201
  • 2
  • 4
  • 12
  • Actually, the question is not exactly the same as referred one. Here OP asks how to convert a Milliseconds String not just milliseconds. – Oleksandr Bondarenko Aug 15 '12 at 12:54
  • Search SO before you post a question. @OleksandrBondarenko still plenty of questions asked about this before. – Anders Metnik Aug 15 '12 at 12:59
  • @OleksandrBondarenko Normally I'd be open to reopening this, but isn't this splitting hairs? – casperOne Aug 15 '12 at 13:31
  • I searched half an hour and also saw that topics. The solutions there didn't work for me. – JohnD Aug 15 '12 at 13:36
  • @JohnD In what way they didn't work? You're asking a question and not showing at all that you actually made some research first, it's normal that it gets marked as duplicated. – José Luis Aug 15 '12 at 13:40
  • The problem is that there are letters is my milliseconds values (see above). When i remove those letters the date - of course - is incorrect. The solution in the other topic can't handle the letters. – JohnD Aug 15 '12 at 14:01
  • Actually OP's question can be reduced to how to convert some String value to long. This is what he's interested in and that's something he didn't find in the answers about converting long to Date string. – Oleksandr Bondarenko Aug 15 '12 at 14:12
  • No, not really. I already parsed the string to long. EDIT: I fear there are some misunderstoods again. First of, the milliseconds come as string. I parse the string to long and convert it back to string (which should be the formatted date). – JohnD Aug 15 '12 at 14:14
  • This doesn't follow from your question. – Oleksandr Bondarenko Aug 15 '12 at 14:15
  • Yes, i hoped there is an easier solution than parsing it to long first. If the milliseconds string can be converted to date string it would be great. Obviously nobody knows how to do that else we wouldn't just comment and comment and comment. – JohnD Aug 15 '12 at 14:19

1 Answers1

6

Hope this helps how to convert milliseconds to date format in android?

 private String getDate(long milliSeconds, String dateFormat)
    {
        // Create a DateFormatter object for displaying date in specified format.
        DateFormat formatter = new SimpleDateFormat(dateFormat);

        // Create a calendar object that will convert the date and time value in milliseconds to date. 
         Calendar calendar = Calendar.getInstance();
         calendar.setTimeInMillis(milliSeconds);
         return formatter.format(calendar.getTime());
    }
Community
  • 1
  • 1
Thomas Tran
  • 467
  • 4
  • 8
  • If you find a duplicate question on Stack Overflow, please don't answer but just leave a comment pointing to the question and flag it as a possible duplicate. – ChrisF Aug 15 '12 at 12:42
  • thank you ChrisF, i will do thatfor later comments. – Thomas Tran Aug 15 '12 at 12:43