Seems like there should be an easy solution to this problem, yet I
can’t seem to find one.
Here is the issue:
How do you assign a time zone to a Time object that results from a
parsed date/time string?
- I receive a date time string from a date picker widget that does not
include time zone info (i.e. “Mon May 11 18:24:37 2009”).
- Time zone for this date is known and may be different than what’s
local to the user
- date/time is stored in the DB as unix time (i.e. 1242075962)
- time zone is stored in the DB in tz format i(i.e. ‘America/
- I would like to be able to take a given date with its known time
zone and calculate the equivalent unix time value.
now = Time.now
=> Mon May 11 18:24:37 -0400 2009
parsed = DateTime.parse(“Mon May 11 18:24:37 2009”)
=> Mon, 11 May 2009 18:24:37 +0000
=> Mon May 11 18:24:37 UTC 2009
=> Mon May 11 14:24:37 -0400 2009
It seems there should be a way to append the time zone to the string
before it is parsed or to associate the parsed time with a time zone
(without converting the time to the zone), however I can’t seem to
find an answer.
Any help would be greatly appreciated