title: convert  date time from one timezone to another in android
body: <p>I am using smack api for instance messages.I want to send the current time with the messages.So i have set the current time as message subject.and then get that time on receiver side.But the problem is that message subject should be string so i have convert the date time to string at sender side and then again convert from string to date time on receiver side.I want the sender's date time should be convert as per receiver's Timezone.I have wrote the code as below but i can't convert the date time to receiver's Timezone's date time.</p>
  
  <pre><code>//sender side
  Calendar c = Calendar.getInstance(); 
  SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzzz yyyy");
  String strdt= formatter.format(c.getTime());
  message.setSubject(strdt);
  </code></pre>
  
  <p>receiver side</p>
  
  <pre><code>TimeZone tz = TimeZone.getDefault();
  String strzone=tz.getDisplayName(false, TimeZone.SHORT);
  String str=message.getSubject();
  Date expiry = null;
  SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzzz yyyy");
                   formatter.setTimeZone(TimeZone.getTimeZone(strzone));
          try { 
                  expiry = formatter.parse(str);
                    }
            catch (Exception e) 
                  {e.printStackTrace();}
  
  SimpleDateFormat df = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzzz yyyy");
              df.setTimeZone(TimeZone.getTimeZone(strzone));  
  String formattedDate1= df.format(expiry);  
  Log.i("receiving time",formattedDate1);
  </code></pre>
  
  <p>i got one output like</p>
  
  <p>message subject=>  Wed Aug 22 13:35:13 GMT+00:00 2012</p>
  
  <p>after convert from string to date =>  Wed Aug 22 07:35:13 MDT 2012</p>
  
  <p>after set the time zone of receiver => Wed Aug 22 06:35:13 GMT-07:00 2012</p>
  
  <p>actual receiver side time => Wed Aug 22 06:39:56 MDT 2012</p>
  
  <p><strong>Edit</strong></p>
  
  <p>Actually i want to send the sender's time to receiver and on receiver side the should be convert as per receiver's time zone.as describe above the receiver's actual time is different than the converting time.So please if you have different code then please post here.</p>