locale date & time to utc and then utc to locale date & time
<p>I am trying to convert locale time to utc, and then utc to locale time. But I am not getting the result. Plz help me.</p>

<pre><code>public class DateDemo
{

public static void main(String args[])
{
    DateFormat dateFormatter = 
               DateFormat.getDateTimeInstance
                 (DateFormat.SHORT, DateFormat.SHORT, Locale.getDefault());

    TimeZone.setDefault(TimeZone.getDefault());

    SimpleDateFormat simpleDateFormatter = new SimpleDateFormat("dd/MM/yyyy");
    SimpleDateFormat simpleTimeFormatter = new SimpleDateFormat("hh:mm:ss a");

    Date today = new Date();
    String localeFormattedInTime = dateFormatter.format(today);

    try
    {
        Date parsedDate = dateFormatter.parse(localeFormattedInTime);
        System.out.println("Locale:" + localeFormattedInTime);
        System.out.println("After parsing a date: " + parsedDate);

        simpleDateFormatter.setTimeZone(TimeZone.getDefault());
        simpleTimeFormatter.setTimeZone(TimeZone.getDefault());

        String date = simpleDateFormatter.format(today);
        String time = simpleTimeFormatter.format(today);
        System.out.println("Today's only date: " + date);
        System.out.println("Today's only time: " + time);

        //// Locale to UTC converting

        simpleDateFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
        simpleTimeFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));

        String utcDate = simpleDateFormatter.format(today);
        String utcTime = simpleTimeFormatter.format(today);
        System.out.println("Convert into UTC's date: " + utcDate);
        System.out.println("Convert into UTC's only time: " + utcTime);

         //// UTC to locale converting

        simpleDateFormatter.setTimeZone(TimeZone.getDefault());
        simpleTimeFormatter.setTimeZone(TimeZone.getDefault());

        Date getDate = simpleDateFormatter.parse(utcDate);
        Date getTime = simpleTimeFormatter.parse(utcTime);

        String getLocalDate = simpleDateFormatter.format(getDate);
        String getLocalTime = simpleTimeFormatter.format(getTime);
        System.out.println("Get local date: " + getLocalDate);
        System.out.println("Get local time: " + getLocalTime);

    } catch (ParseException e) {
        e.printStackTrace();
    }
  }
 }
</code></pre>

<p>Actually I am sending local date &amp; time to the web service, and then when require I need to retrieve the utc date &amp; time and then convert into locale date &amp; time (i.e. user's local settings). Please help me.</p>

<p>==================================================================================</p>

<p>After Saksak &amp; ADTC answers:</p>

<p>For the code fragment, utc date_time(what is actually coming is "GMT-5hr"r because database is in usa may be) is the input, and I want to get Local date_time as output. But this following segment is still giving GMT-5hr timing. </p>

<p>SimpleDateFormat simpleDateTimeFormatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss a");</p>

<p>....</p>

<p>Date inDateTime = simpleDateTimeFormatter.parse(intent.getExtras().getString("inTime")); Date outDateTime = simpleDateTimeFormatter.parse(intent.getExtras().getString("outTime"));</p>

<p>simpleDateTimeFormatter.setTimeZone(TimeZone.getDefault()); simpleDateTimeFormatter.setTimeZone(simpleDateTimeFormatter.getTimeZone());</p>

<p>//TimeZone tzTimeZone = TimeZone.getDefault();</p>

<p>//System.out.println("Current time zone: " + tzTimeZone.getDisplayName());</p>

<p>String getLocalInTimeString = simpleDateTimeFormatter.format(inDateTime); </p>

<p>String getLocalOutTimeString = simpleDateTimeFormatter.format(outDateTime);</p>

<p>My Ques: getLocalInTimeString &amp; getLocalOutTimeString still showing GMT-5hr timing. What's wrong here? Do I need to set any other things?</p>
