MadTech MadTech - 1 year ago 73
Android Question

UTC time into Local TIme in Android

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?

Here Some Code I have tried:

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

Assume aDate contain
Jul 16, 2013 12:08:59 AM

Answer Source

Here's my attempt:

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

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