Reputation: 159
I am using Kendo UI DateTimePicker and i faced with binding issue. I am getting data from json then i creating new js date based on the json value and bind it. Actual result is that the date is converted to local timezone. Can i disable conversion to local timezone?
Upvotes: 1
Views: 7423
Reputation: 4336
You can do this to add a useUtc option to your code that will always return the date in Utc:
kendo.ui.DatePicker.prototype.valueOld = kendo.ui.DatePicker.prototype.value;
kendo.ui.DatePicker.prototype.value = function (e) {
var val = this._value;
if (val != null && this.options != null && this.options.useUtc) {
this._value = new Date(Date.UTC(val.getFullYear(), val.getMonth(), val.getDate()));
}
return this.valueOld(e);
}
kendo.ui.DateTimePicker.prototype.valueOld = kendo.ui.DateTimePicker.prototype.value;
kendo.ui.DateTimePicker.prototype.value = function (e) {
var val = this._value;
if (val != null && this.options != null && this.options.useUtc) {
this._value = new Date(Date.UTC(val.getFullYear(), val.getMonth(), val.getDate(), val.getHours(), val.getMinutes(), val.getSeconds(), val.getMilliseconds()));
}
return this.valueOld(e);
}
Upvotes: 3
Reputation: 3091
The DateTimePicker does not perform any conversion. I expect that your date does not have time zone specificator and when you creating new js date this value considered as UTC and converted to local. To solve this problem you can simply bind date from json without creating new js date.
Upvotes: 3