101
{ USER }
posts: 55
last: 09-Apr-2008
TITLE: Convert Java date to GMT
DESCRIPTION: Convert Java date to GMT
Submitted: 09-Apr-2008 10:50:52 ( 38w 5d 19h ago ) Language: Java (*.java)
Views: 144 Lines of Code: 28 LINES
Rating:
rate: star1
star2
star3
star4
star5
dstar1
dstar2
dstar3
dstar4
dstar5  ( rated! )
  { 0.00 / 5 }
Difficulty: Intermediate
Bookmark
/* Author: 101
   Date: 09-04-2008
   Filename: 
   Description: Convert Java date to GMT
   History: 
*/


private static Date cvtToGmt( Date date )
{
   TimeZone tz = TimeZone.getDefault();
   Date ret = new Date( date.getTime() - tz.getRawOffset() );

   // if we're now in DST, back off by the delta.  Note that we're checking the GMT date, this is the KEY.
   if ( tz.inDaylightTime( ret ))
   {
      Date dstDate = new Date( ret.getTime() - tz.getDSTSavings() );

      // check to make sure we haven't crossed back into standard time
      // this happens when we're on the cusp of DST (7pm the day before the change for PDT)
      if ( tz.inDaylightTime( dstDate ))
      {
         ret = dstDate;
      }
   }

   return ret;
}