In Ruby or Rails, what is the best way to convert Eastern Time to UTC? -


i'm not referring

mydatetime = datetime.now mydatetime.new_offset(rational(0, 24)) 

or

time.now.utc 

what have text date given in eastern time.

i can convert text date datetime. let's call eastern_date_time.

now, have variable containing datetime, nothing knows it's eastern besides us. converting ourselves quite onerous. if date in daylight savings time (dst) (march 8 november 1st year), we'd have add 4 hours our eastern_date_time var utc, , if date in standard time (st) we'd have add 5 hours our eastern_date_time variable.

how can specify have eastern datetime, , convert utc... determine if date in dst/st, , apply 4 or 5 hours properly?

i want convert sort of date utc, storage in database.

edit:

using `in_time_zone', i'm unable convert eastern text time utc. how can achieve objective? example...

text_time = "nov 27, 2015 4:30 pm" #given eastern myeasterndatetime = datetime.parse text_time # => fri, 27 nov 2015 16:30:00 +0000  #now need specify myeasterndatetime in fact eastern. however, it's our default utc. if use in_time_zone, converts date @ utc eastern myeasterndatetime.in_time_zone('eastern time (us & canada)') # => fri, 27 nov 2015 11:30:00 est -05:00  myeasterndatetime.utc # => fri, 27 nov 2015 16:30:00 +0000  

that's not want. have specify myeasterdatetime in fact eastern... when myeasterdatetime.utc on 16:30:00 end getting 20:30:00.

how can accomplish this?

there time_in_zone method in datetime class:

now.time_in_zone('utc') 

it has since been renamed in_time_zone:

datetime.now.in_time_zone('us/pacific')  => wed, 22 apr 2015 12:36:33 pdt -07:00  

Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -