From: Brian Candler Date: 2010-08-21T04:54:02+09:00 Subject: Re: Dealing with dates & timezones Stuart Clarke wrote: > Hey all, > > I was wondering if I could ask for some advice regarding dates. I have a > file that contains lots of date values formatted like so: > > Sunday, 15 August 2010 05:46:50 o'clock BST Just sub out the "o'clock" and you should be fine. >> require 'time' => true >> t = Time.parse("Sunday, 15 August 2010 05:46:50 BST") => Sun Aug 15 05:46:50 +0100 2010 >> t.gmtime => Sun Aug 15 04:46:50 UTC 2010 >> t.localtime => Sun Aug 15 05:46:50 +0100 2010 >> t.zone => "BST" Note that t stores the universal (UTC/GMT) time, but remembers the local zone is BST; from that you can format and print either. Internally they are both represented as in UTC as the number of seconds from midnight on Jan 1, 1970. >> t.to_i => 1281847610 >> t.gmtime.to_i => 1281847610 >> t.localtime.to_i => 1281847610 >> t.gmtoff => 3600 > I want basically out these dates as follows, applying the necessary time > zone bias: > > 15/08/2010 06:46:50 (because it is BST we add the hour) I think you have made a mistake there. If the time is 05:46:50 BST, as the original string said, then that's the time in BST. Since BST is GMT+1 (in the summer anyway), then the time is also 04:46:50 in GMT. It is 06:46:50 local time in France (Western European Time, GMT+2 in summer) HTH, Brian. -- Posted via http://www.ruby-forum.com/.