Convert UTC into Local Time on Android

后端 未结 5 1652
眼角桃花
眼角桃花 2020-11-29 04:26

In my project, I have get the API response in json format. I get a string value of time in UTC time format like this Jul 16, 2013 12:08:59 AM.
I need to cha

5条回答
  •  时光取名叫无心
    2020-11-29 04:47

    Use the following code.

    TimeZone defaultTimeZone = TimeZone.getDefault();
    String strDefaultTimeZone = defaultTimeZone.getDisplayName(false, TimeZone.SHORT);
    
    //The code you use
    String aDate = getValue("dateTime", aEventJson);
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMM dd, yyyy HH:mm:ss z");
    simpleDateFormat.setTimeZone(TimeZone.getTimeZone(strDefaultTimeZone));
    String formattedDate = simpleDateFormat.format(aDate);
    

    This should work.

提交回复
热议问题