Skip to content

Instantly share code, notes, and snippets.

@jayuen
Last active December 21, 2015 17:08
Show Gist options
  • Save jayuen/6338077 to your computer and use it in GitHub Desktop.
Save jayuen/6338077 to your computer and use it in GitHub Desktop.
Converting a local equivalent date into a DateWithTimezone
// generate a string that only has the time portion
var strWithoutTimezone = moment(localEquivalent).format("YYYY-MM-DDTHH:mm:ss")
// extract out the site's timezone identifier (DateWithTimezone.getTimezone() stores the site's timezone)
var timezone = moment.tz(DateWithTimezone.getTimezone()).format("Z")
// create a moment in the site's timezone and use it to initialize a `DateWithTimezone`
return new DateWithTimezone(moment(strWithoutTimezone + timezone))
@samwalshnz
Copy link

Hi there, any chance you'd be able to upload the DateWithTimezone object as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment