UTC日期时间在Android设备本地日期时间转换 [英] UTC datetime to device local datetime conversion in android

查看:1147
本文介绍了UTC日期时间在Android设备本地日期时间转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我更新到Android的发展。我已收到UTC日期时间,如2014-03-03T01:02:19 + 00:00。我想将其转换为设备本地时区中的机器人。我看到它,但无法理解我应该在哪里地方,code一些SO职位。任何帮助将是AP preciated。先谢谢了。


解决方案

 私人字符串getDateTimeInDeviceLocale(字符串日期)
    {
        日期desiredDate = NULL;
        SimpleDateFormat的SimpleDateFormat的=新的SimpleDateFormat(YYYY-MM-dd'T'HH:MM:SS);
        尝试
        {
            desiredDate = simpleDateFormat.parse(日期);
            SimpleDateFormat的desiredSimpleDateFormat =新的SimpleDateFormat(MMMM-DD-YYYY);
            desiredSimpleDateFormat.format(desiredDate);
        }
        赶上(ParseException的E)
        {
            e.printStackTrace();
        }
        返回desiredDate.toString();
    }

I am newer to android development. I have received UTC datetime such as "2014-03-03T01:02:19+00:00". I want to convert it to device local timezone in android. I see some SO posts about it but unable to understand where should i place that code. Any help would be appreciated. Thanks in advance.

解决方案

private String getDateTimeInDeviceLocale(String date) 
    {
        Date desiredDate = null;
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        try 
        {
            desiredDate = simpleDateFormat.parse(date);
            SimpleDateFormat desiredSimpleDateFormat = new SimpleDateFormat("MMMM-dd-yyyy");
            desiredSimpleDateFormat.format(desiredDate);
        } 
        catch (ParseException e) 
        {
            e.printStackTrace();
        }
        return desiredDate.toString();
    }

这篇关于UTC日期时间在Android设备本地日期时间转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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