Tempus-dominus: Do not support Timezone?

Created on 10 Aug 2016  路  3Comments  路  Source: Eonasdan/tempus-dominus

After a test, I draw a conclusion

  1. It parse the time string(+0800) into UTC
  2. It will use the timezone(+0800) of my computer when I select a time

And I could not find an option which can specify the Timezone, is this a bug, or have I missing sth?

The versions are

  • momentjs 2.11.1
  • bootstrap-datetimepicker 4.14.30

Most helpful comment

Use moment.tz.setDefault('TimeZoneName'); to set the default timezone you want to use (e.g. moment.tz.setDefault('UTC'); to use UTC as default). You will need the moment-timezone package as mentioned by @thw0rted .

You can then convert the timezone to whatever timezone you want:

// guess current client's timezone
var guess = moment.tz.guess();

// get moment object from datetimepicker
var datetime = $('#datetimepicker').data("DateTimePicker").date();

// convert moment object's timezone
datetime.tz(guess);

// set moment object as new value for datetimepicker
$('#datetimepicker').data("DateTimePicker").date(datetime); 

// also tell datetimepicker about the used timezone
$('#datetimepicker').data("DateTimePicker").timeZone(guess); 

All 3 comments

There is a timeZone option but it is ignored if you are not also using the moment-timezone package. My (npm-managed) [email protected] wants moment-timezone ^0.4.0 but for some reason I had to manually install it. Once I did, I was able to specify a timeZone in the options hash.

This is not documented. ( #2118 )

Use moment.tz.setDefault('TimeZoneName'); to set the default timezone you want to use (e.g. moment.tz.setDefault('UTC'); to use UTC as default). You will need the moment-timezone package as mentioned by @thw0rted .

You can then convert the timezone to whatever timezone you want:

// guess current client's timezone
var guess = moment.tz.guess();

// get moment object from datetimepicker
var datetime = $('#datetimepicker').data("DateTimePicker").date();

// convert moment object's timezone
datetime.tz(guess);

// set moment object as new value for datetimepicker
$('#datetimepicker').data("DateTimePicker").date(datetime); 

// also tell datetimepicker about the used timezone
$('#datetimepicker').data("DateTimePicker").timeZone(guess); 

Hi, as @thw0rted this option is not documented but can actually be use I made a fiddle a while ago, and should bw working http://jsfiddle.net/tyw9dnhb/1/

Was this page helpful?
0 / 5 - 0 ratings