UTC时间成安卓当地时间

编程入门 行业动态 更新时间:2024-10-28 21:26:31
本文介绍了UTC时间成安卓当地时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的项目,我已经得到JSON格式的API响应。我得到的时间,那UTC时间格式的字符串值 2013年7月16日上午12时08分59秒。我需要更改此为本地时间。 这就是以往我们使用这个程序需要展示我们的本地时间。怎么办?

In my project, i have get the api response in Json format. I get the string value of time in UTC time format of that is Jul 16, 2013 12:08:59 AM. I need to change this into Local time. That is where ever we use this app need to show our local time. How to I do?

下面一些code我曾尝试:

Here Some Code I have tried:

String aDate = getValue("dateTime", aEventJson); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM dd, yyyy HH:mm:ss z"); simpleDateFormat.setTimeZone(TimeZone.getDefault()); String formattedDate = simpleDateFormat.format(aDate);

假设A日期包含 2013年7月16日上午十二点08分59秒

推荐答案

下面是我的尝试:

String dateStr = "Jul 16, 2013 12:08:59 AM"; SimpleDateFormat df = new SimpleDateFormat("MMM dd, yyyy HH:mm:ss a"); df.setTimeZone(TimeZone.getTimeZone("UTC")); Date date = df.parse(dateStr); df.setTimeZone(TimeZone.getDefault()); String formattedDate = df.format(date);

另外,还要注意一为AM / PM标记...

Also notice the "a" for the am/pm marker...

更多推荐

UTC时间成安卓当地时间

本文发布于:2023-10-17 13:29:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1501069.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:成安   当地时间   时间   UTC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!