In current timezone implemnetation in the method getMoment
https://github.com/Eonasdan/bootstrap-datetimepicker/blob/master/src/js/bootstrap-datetimepicker.js#L157
there is a code to compare configured timezone with browser timezone.
This is plainly wrong. if timezone is set on datepicker we should not consider browser timezone at all, and assume that provided date string is already in the configured timezone.
The current implementation leads to issues, when you have different timezone configured in the picker and in the browser. Each time you open a datepicker your time will change.
I fixed it by changing
if (tzEnabled) {
currentZoneOffset = moment().tz(options.timeZone).utcOffset();
incomingZoneOffset = moment(d, parseFormats, options.useStrict).utcOffset();
if (incomingZoneOffset !== currentZoneOffset) {
timeZoneIndicator = moment().tz(options.timeZone).format('Z');
dateWithTimeZoneInfo = moment(d, parseFormats, options.useStrict).format('YYYY-MM-DD[T]HH:mm:ss') + timeZoneIndicator;
returnMoment = moment(dateWithTimeZoneInfo, parseFormats, options.useStrict).tz(options.timeZone);
} else {
returnMoment = moment(d, parseFormats, options.useStrict).tz(options.timeZone);
}
} else {
to
if (tzEnabled) {
returnMoment = moment.tz(d, parseFormats, options.timeZone);
} else {
this will also resolve issue: https://github.com/Eonasdan/bootstrap-datetimepicker/issues/1355
just found out that the same solution is used in pull request https://github.com/Eonasdan/bootstrap-datetimepicker/pull/1329 for issue https://github.com/Eonasdan/bootstrap-datetimepicker/issues/1326
@tmotyl You saved my day, thank's!
+1 to fix this.
took me hours to find out what the problem was. who would have guessed that the timezones plugin was the cause.
looks like the fix was merged to development branch already https://github.com/Eonasdan/bootstrap-datetimepicker/commit/ac17a1c7e3bc291448cce4cafa454e98140c8da6
Hi folks, great plugin.
I ran into similar timezone issues. Is this released yet? Also any example on how we're meant to be using timezones, please?
When I get a dp.onchange that date has a timezone of +00:00 event though I am in timezone +11:001
thanks
+1 timezone examples required
This update is still missing on the master branch, right? When will it be included?
+1. Any news on this?
I am glad to find this, it was driving me nuts. Thanks.
+1 for a release with this fix!
Any update on this?
It would be good to see this in the master branch
This appears to be working as of the latest release version, it's just not documented! Pass in timeZone (capital "Z") into the init options.
As @rchanou said this has been solved here a Fiddle
Even If you don't set the default date it will take the time of the specified timeZone
i.e:
timeZone: 'Europe/London'
Most helpful comment
This update is still missing on the master branch, right? When will it be included?