<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: date code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 07:44:04 GMT</pubDate>
    <description>DZone Snippets: date code</description>
    <item>
      <title>Convert Java date to GMT</title>
      <link>http://snippets.dzone.com/posts/show/5288</link>
      <description>This function converts a local date to GMT.  This version corrects the bug common to this type of conversion where the date is incorrectly converted when the time is close to the DST crossover.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;private static Date cvtToGmt( Date date )&lt;br /&gt;{&lt;br /&gt;   TimeZone tz = TimeZone.getDefault();&lt;br /&gt;   Date ret = new Date( date.getTime() - tz.getRawOffset() );&lt;br /&gt;&lt;br /&gt;   // if we are now in DST, back off by the delta.  Note that we are checking the GMT date, this is the KEY.&lt;br /&gt;   if ( tz.inDaylightTime( ret ))&lt;br /&gt;   {&lt;br /&gt;      Date dstDate = new Date( ret.getTime() - tz.getDSTSavings() );&lt;br /&gt;&lt;br /&gt;      // check to make sure we have not crossed back into standard time&lt;br /&gt;      // this happens when we are on the cusp of DST (7pm the day before the change for PDT)&lt;br /&gt;      if ( tz.inDaylightTime( dstDate ))&lt;br /&gt;      {&lt;br /&gt;         ret = dstDate;&lt;br /&gt;      }&lt;br /&gt;   }&lt;br /&gt;&lt;br /&gt;   return ret;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 28 Mar 2008 20:56:15 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5288</guid>
      <author>frost137 (Douglas Wyatt)</author>
    </item>
  </channel>
</rss>
