如何在Android上将UTC日期转换为语言环境GMT时间 [英] how to convert UTC date to locale GMT time on android

查看:127
本文介绍了如何在Android上将UTC日期转换为语言环境GMT时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个日期字符串:2016-04-26T09:14:10.477Z,它位于UTC时区.我想将其转换为用户本地时区,所以如果它是格林尼治标准时间+02:00,则我想要一个值为2016-04-26T11:14:10.477Z的日期(注意将9更改为11).

I have this date string : 2016-04-26T09:14:10.477Z which is in UTC timezone. I want to convert it to the user local Timezone, so if it is GMT +02:00, I want a date with a value of 2016-04-26T11:14:10.477Z (note the 9 changes to 11).

到目前为止,我一直在使用它:

I've been using this so far :

val sdf = SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.getDefault())
val now = Date()

val limit = sdf.parse(coupon.usedAt)

这是limit = Tue Apr 26 09:14:10 GMT+02:00 2016,我想这是不正确的.

Here limit = Tue Apr 26 09:14:10 GMT+02:00 2016 which is not correct I suppose.

那么我该如何正确转换呢?谢谢!

So how can I convert it correctly? Thanks!

我的问题与

Edit : my question differs from this one, since I need to use the object SimpleDateFormat and not the Date one

推荐答案

尝试一下

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

这篇关于如何在Android上将UTC日期转换为语言环境GMT时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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