UTC datetime to device local datetime conversion i

2019-09-17 01:41发布

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条回答
在下西门庆
2楼-- · 2019-09-17 01:55
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();
    }
查看更多
登录 后发表回答