我正在使用日期时间选择器 here 。如何设置“现在”按钮,以便它设置现在的时间 UTC,而不是每个浏览器的当前时间?
最佳答案
打开 jQuery timepicker 插件文件并转到以下函数
/*
* override "Today" button to also grab the time.
*/
$.datepicker._base_gotoToday = $.datepicker._gotoToday;
$.datepicker._gotoToday = function (id) {
var inst = this._getInst($(id)[0]),
$dp = inst.dpDiv;
this._base_gotoToday(id);
var tp_inst = this._get(inst, 'timepicker');
selectLocalTimezone(tp_inst);
var now = new Date();
this._setTime(inst, now);
$('.ui-datepicker-today', $dp).click();
};
只需添加以下更改即可,
var now = new Date();
var utcNow = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());
this._setTime(inst, utcNow);
关于jquery - 如何在 jquery UI datetimepicker 上设置 'Now' 按钮来设置 UTC 时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13479416/