UTC datetime to device local datetime conversion in android [closed]

不羁岁月 提交于 2019-12-13 03:36:23

问题


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.


回答1:


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();
    }


来源:https://stackoverflow.com/questions/26009224/utc-datetime-to-device-local-datetime-conversion-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!