Parsing time string and changing timezone
<p>I am retrieving data from a webservice that provides a timestamp in the form of <code>HH:mm:ss</code> I am using SimpleDateFormat to convert this string into a date object then change its timezone if needed and also convert it from 24hour to 12 hour time.</p>

<p>Problem: When a time is fed in for 12am it looks like this <code>00:00:00</code>
so 12:05 is <code>00:05:00</code>
When i get the results they look like this.</p>

<p>times fed in <code>22:00:00</code> to <code>00:01:00</code></p>

<p>times retrieved <code>10:00 pm</code> to <code>0:01 am</code></p>

<p>I have been looking around to see if there is a way to fix it but i feel like i will need to make a special case and parse the string myself if it has a 0 in the hours place. </p>

<p>Any help would be greatly appreciated. </p>

<pre><code>public String parseTime(String time) {
    String mTime = null;
    TimeZone thisTimeZone = TimeZone.getDefault();
    TimeZone ourTimeZone = TimeZone.getTimeZone("America/Los_Angeles");
    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss", Locale.US);
    SimpleDateFormat sdfThisTimeZone = new SimpleDateFormat("K:mm:a",
            Locale.getDefault());

    Date date = null;
    sdfThisTimeZone.setTimeZone(thisTimeZone);
    sdf.setTimeZone(ourTimeZone);
    try {
        date = sdf.parse(time);
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    mTime = sdfThisTimeZone.format(date.getTime());
//**********************************New: Does Not Work********************************
            DecimalFormat nft = new DecimalFormat("00"); mTime = nft.format(mTime);
//**********************************New **********************************************
    return mTime;
}
</code></pre>

<p>I have tried the line using DecimalFormat but i just copied it into the code for now to see if it would work. Unfortunately it made my app crash. The code that i have posted is executed inside an Async Task so i am not sure if that makes any difference but still thankyou for your help. Eventually i will solve this. But for now it is such a small detail that only occurs for 1 hour at 12am that i am moving on to bigger issues. If anyone can shed some light on this that would be awesome.</p>
