4

I have browser time zone in a cookie variable and date in start_date variable as string . say cookie['browser_zone']="Asia/kolkata" & start_date = "2017/12/31 03:00:00" how can I convert above date to with this time zone to UTC time zone.

  • have you tried ruby strptime – Sujan Adiga Dec 04 '17 at 18:14
  • 1
    Possible duplicate of [Rails: How to parse date-time string into a specific time zone](https://stackoverflow.com/questions/10091959/rails-how-to-parse-date-time-string-into-a-specific-time-zone) – patkoperwas Dec 04 '17 at 19:13

1 Answers1

3

Use ActiveSupport::TimeZone to parse the time into the correct time zone, then convert it to UTC

ActiveSupport::TimeZone["Asia/Kolkata"].parse("2017/12/31 03:00:00").utc
=> 2017-12-30 21:30:00 UTC
patkoperwas
  • 1,341
  • 10
  • 14