如何在jQuery datetimepicker中获取UTC时间 [英] How to obtain utc time in jQuery datetimepicker

查看:434
本文介绍了如何在jQuery datetimepicker中获取UTC时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 jQuery datetimepicker 来获取日期和时间数据. 我能够解决大部分问题(格式,显示等).但是,我无法以UTC格式获取日期和时间.我只能以本地格式获取日期和时间.

I am using the trying this jQuery datetimepicker to obtain date and time data. I am able to get most of the things out (format, display, etc). However, I wasn't able to get the date and time in UTC format. I am only able to obtain the date and time in local format.

有人知道如何对其进行修改以获取日期和时间吗? 或删除弹出窗口中的现在"按钮?

Does anyone know how to modify it to get the date and time? or remove off the "Now" button in the popup?

推荐答案

我今天遇到了同样的问题,并发现了这个旧线程.单击现在"按钮时,您可以覆盖$ .datepicker._gotoToday以使用UTC时间.

I ran into the same issue today, and found this old thread. You can override $.datepicker._gotoToday to use UTC Time when you click the "now" button.

//make the now button go to "now" in utc, not local
$.datepicker._gotoToday = function(id) {
  var inst = this._getInst($(id)[0]),
      $dp = inst.dpDiv;
  this._base_gotoToday(id);
  var tp_inst = this._get(inst, 'timepicker');
  //removed -> selectLocalTimeZone(tp_inst);
  var now = new Date();
  var now_utc = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(),  now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());
  this._setTime(inst, now_utc);
  $('.ui-datepicker-today', $dp).click();
};

这篇关于如何在jQuery datetimepicker中获取UTC时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆