我有像“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);
之后,您的日期格式应该完成其余的工作。
关于java - 如何将此毫秒转换为时间(hh :mm a)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8657708/