繁体   English   中英

如何将毫秒转换为时间(hh:mm a)?

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

我有毫秒,例如“ 1325085788”,我想将其转换为hh:mm a。 我知道这一点,但要给我时间01:34 PM而不是08:53 PM。什么问题?

我的代码是::

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);

没有时区问题,因为它给了我iPhone应用程序中的当前时间(印度)

1325085788不是毫秒。 几秒钟 您的期望值降低了几个数量级,但这可以在给定的毫秒内为您提供正确的时间。

如果您有几秒钟的时间并想去约会,则类似以下内容:

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

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

之后,您的日期格式应完成其余工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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