Skip to content

Instantly share code, notes, and snippets.

@etozzato
Last active August 29, 2015 14:08
Show Gist options
  • Save etozzato/f67e2adb0975b6a06d66 to your computer and use it in GitHub Desktop.
Save etozzato/f67e2adb0975b6a06d66 to your computer and use it in GitHub Desktop.
Working with ActiveSupport::TimeZone
// MomentJS can use different types of timezone offset
// including the one obtained by ActiveSupport::TimeZone
var timezone_offset = "+01:00";
console.log(moment().zone(timezone_offset).format('LLLL'));
> Tuesday, October 28 2014 7:51 PM
console.log(moment().format('LLLL'));
> Tuesday, October 28 2014 11:51 AM
# Good to know for the future when
# dealing with daylight saving time
timezone = 'Rome'
$ ActiveSupport::TimeZone[timezone].now.formatted_offset
> "+01:00"
$ ActiveSupport::TimeZone[timezone].formatted_offset
> "+01:00"
timezone = 'Pacific Time (US & Canada)'
$ ActiveSupport::TimeZone[timezone].now.formatted_offset
> "+07:00"
$ ActiveSupport::TimeZone[timezone].formatted_offset
> "+08:00"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment