ruby on rails - Converting datetime with one timezone to utc -


in rails4 app, have date given in 2 strings, 1 gives timestamp, while other gives timezone in:

a = "04/23/2014 04:00" b = "eastern time (us & canada)" 

i want convert date utc, can save in utc

"2014-04-23 08:00:00 utc" 

what best way it?

using strptime method on rails datetime class, can parse datetime object string containing both time , timezone (timezone passed via %z directive). there, can convert time utc:

a = "04/23/2014 04:00" b = "eastern time (us & canada)"  datetime_with_tz = datetime.strptime([a, b].join(' '), "%m/%d/%y %h:%m %z") #=> wed, 23 apr 2014 04:00:00 -0500  datetime_with_tz.utc #=> wed, 23 apr 2014 09:00:00 +0000  

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -