vendredi 26 décembre 2014

Get Parseable Timezone


I am using Momentjs and Momentjs Timezone to handle dates / timezones.


I'm attempting to have a date that is input from a user in a specific time zone and convert it to the local time in their own time zone. It doesn't look like Moment's Timezone library supports the new Date().getTimezoneOffset() format for setting the time zone.



function calculateLocalTime(e) {
var currentTz = new Date().getTimezoneOffset(),
fromDate = moment.tz(this.value, 'GMT'),
toDate = fromDate.tz(currentTz);

$('to-time').val(toDate.format(dateFormat));
}


I've also attempted to extract the three-letter time zone from the normal Date object as well, but that doesn't seem to be supported either.



function calculateLocalTime(e) {
var currentTz = new Date().toString().split(' ').pop().replace(/\(/gi, '').replace(/\)/gi, ''),
fromDate = moment.tz(this.value, 'GMT'),
toDate = fromDate.tz(currentTz);

$('to-time').val(toDate.format(dateFormat));
}


Any idea on how I should be doing this using Moment?





Aucun commentaire:

Enregistrer un commentaire