UTC转换为当前区域设置的时间转换为、区域、时间、UTC

由网友(撸至呻)分享简介:我下载从web服务的一些JSON数据。在此JSON我有一些日期/时间值。在UTC一切。我该如何解析这个日期字符串所以结果Date对象是在当前区域设置?例如:服务器返回2011-05-18 16时35分零一秒和我的设备现在应该显示2011-05-18 18时35分01秒(格林尼治标准​​时间+2)我目前的code:的S...

我下载从web服务的一些JSON数据。在此JSON我有一些日期/时间值。在UTC一切。 我该如何解析这个日期字符串所以结果Date对象是在当前区域设置?

例如:服务器返回2011-05-18 16时35分零一秒和我的设备现在应该显示2011-05-18 18时35分01秒(格林尼治标准​​时间+2)

我目前的code:

的SimpleDateFormat SimpleDateFormat的=新的SimpleDateFormat(YYYY-MM-DD HH:MM:SS);
日期指明MyDate = simpleDateFormat.parse(rawQuestion.getString(AskDateTime)); 

解决方案

它有一套时区的方法:

 的SimpleDateFormat SimpleDateFormat的=新的SimpleDateFormat(YYYY-MM-DD HH:MM:SS);
simpleDateFormat.setTimeZone(TimeZone.getTimeZone(UTC));
日期指明MyDate = simpleDateFormat.parse(rawQuestion.getString(AskDateTime));
 
Moment.js 转换 UTC 格式的 2 个小问题

全部完成!

I am downloading some JSON data from a webservice. In this JSON I've got some Date/Time values. Everything in UTC. How can I parse this date string so the result Date object is in the current locale?

For example: the Server returned "2011-05-18 16:35:01" and my device should now display "2011-05-18 18:35:01" (GMT +2)

My current code:

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date myDate = simpleDateFormat.parse(rawQuestion.getString("AskDateTime"));

解决方案

It has a set timezone method:

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
Date myDate = simpleDateFormat.parse(rawQuestion.getString("AskDateTime"));

all done!

阅读全文

相关推荐

最新文章