简体   繁体   中英

How to convert this milliseconds into time (hh:mm a)?

I have milliseconds like "1325085788" i want to convert it on hh:mm a . i know this but return me time 01:34 PM instead of 08:53 PM.Whats problem ?

My code is ::

String created_on = "1325085788";
        String pattern = "hh:mm a";
        SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);

        Date date = new Date(Long.parseLong(created_on));

        String yourFormatedDate = dateFormat.format(date);

        System.out.println("--------> " + yourFormatedDate);

no timezone issue because it give me current time (in india) in iphone app

1325085788 isn't milliseconds. It's seconds. Your expectations are off by a few orders of magnitude, but it's giving you the correct time for the given milliseconds.

If you have seconds and want to go to a Date, then something like this:

import static java.util.concurrent.TimeUnit.*;

String created_on = "1325085788";
long millis = MILLISECONDS.convert(Long.parseLong(created_on), SECONDS);
Date d = new Date(millis);

After that, your date formatting should do the rest of the work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM