UTC转换为当前区域设置的时间 [英] Convert UTC to current locale time

查看:124
本文介绍了UTC转换为当前区域设置的时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载从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));
 

全部完成!

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!

这篇关于UTC转换为当前区域设置的时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆