将毫秒转换为 Joda 日期时间或区域 0000
convert millisecond to Joda Date Time or for zone 0000
请告诉我如何将毫秒转换为 joda 日期时间??
formatter = DateTimeFormat.forPattern("dd/MM/yyyy'T'HH:mm:ss").withZone(DateTimeZone.forOffsetHoursMinutes(00, 00));
甚至尝试过
String millisecond="14235453511"
DateTime.parse(millisecond);
有a constructor that takes milliseconds:
long milliseconds = 14235453511;
DateTime someDate = new DateTime(milliseconds);
你可以使用这个
Calendar calendar = new GregorianCalendar();
DateFormat formatter = new SimpleDateFormat("dd MMM yyyy HH:mm:ss z");
formatter.setCalendar(calendar);
String timeZone = "GMT+2:00";
formatter.setTimeZone(TimeZone.getTimeZone(timeZone));
String time = formatter.format(calendar.getTime());
System.out.println(time);
希望对您有所帮助
@Adam S 给的答案差不多就可以了。但是,我更愿意明确指定时区。如果不指定它,您将获得系统时区中构造的 DateTime
-实例。但是你想要区域“0000”(UTC)?然后寻找这个替代方案 constructor:
String milliseconds = "14235453511";
DateTime someDate = new DateTime(Long.valueOf(milliseconds), DateTimeZone.UTC);
System.out.println(someDate); // 1970-06-14T18:17:33.511Z
请告诉我如何将毫秒转换为 joda 日期时间??
formatter = DateTimeFormat.forPattern("dd/MM/yyyy'T'HH:mm:ss").withZone(DateTimeZone.forOffsetHoursMinutes(00, 00));
甚至尝试过
String millisecond="14235453511"
DateTime.parse(millisecond);
有a constructor that takes milliseconds:
long milliseconds = 14235453511;
DateTime someDate = new DateTime(milliseconds);
你可以使用这个
Calendar calendar = new GregorianCalendar();
DateFormat formatter = new SimpleDateFormat("dd MMM yyyy HH:mm:ss z");
formatter.setCalendar(calendar);
String timeZone = "GMT+2:00";
formatter.setTimeZone(TimeZone.getTimeZone(timeZone));
String time = formatter.format(calendar.getTime());
System.out.println(time);
希望对您有所帮助
@Adam S 给的答案差不多就可以了。但是,我更愿意明确指定时区。如果不指定它,您将获得系统时区中构造的 DateTime
-实例。但是你想要区域“0000”(UTC)?然后寻找这个替代方案 constructor:
String milliseconds = "14235453511";
DateTime someDate = new DateTime(Long.valueOf(milliseconds), DateTimeZone.UTC);
System.out.println(someDate); // 1970-06-14T18:17:33.511Z