From: Stuart Clarke Date: 2010-08-21T05:06:17+09:00 Subject: Re: Dealing with dates & timezones R.. Kumar 1.9.1 OSX wrote: > >> >> tz = TZInfo::Timezone.get(Choice.choices[:from]) >> tz1 = TZInfo::Timezone.get('Asia/Calcutta') >> #local = tz.utc_to_local(Time.utc(2008,9,4,14,00,0)) >> unparsed.each {|timestr| >> puts timestr [1] >> local = tz.local_to_utc(Time.parse(timestr)) >> puts tz1.utc_to_local(local) [2] >> } >> (you would not need to loop. unparsed refers to ARGV on command line) > > Please note in the above program, i am always converting incoming time > to time in Asia/Calcutta. However, the incoming time (time "from" can be > passed on the command line). > > tz is time_zone from > tz1 is time_zone to (calcutta) > > [1] is what the user entered such as "12:00 AM" > [2] is converted time in Asia/Cal. > > I hope this helps. Thanks a lot for getting back to me. The first problem I have noticed but have sorted out is the format of my date using the following code I first convert - "Sunday, 15 August 2010 05:46:50 o'clock BST" into this - "Sun, 15 Aug 2010 05:46:50 +0100" d = "Sunday, 15 August 2010 05:46:50 o'clock BST" dateparts = ParseDate.parsedate("#{d}") d = Time.mktime("#{dateparts[0]}","#{dateparts[1]}","#{dateparts[2]}","#{dateparts[3]}","#{dateparts[4]}","#{dateparts[5]}") done = d.strftime("%a, %d %b %Y %H:%M:%S %Z") I then go into the code you suggested: me =TZInfo::Timezone.get('Europe/London') utctime = Time.parse(done).utc puts me.utc_to_local(utctime) This then gives me Sun Aug 15 06:46:50 UTC 2010 Is my code and logic correct? Many thanks -- Posted via http://www.ruby-forum.com/.