如何在 jQuery 日期时间选择器中设置时区?

问题描述 投票:0回答:3

我正在使用这个 datetimepicker jquery 插件:http://xdsoft.net/jqplugins/datetimepicker/,我不知道如何使用时区。 我看过文档,但找不到。

我尝试做的是类似的事情:

serviceDateTime.datetimepicker({
  lang: 'pt-BR',
  format: 'd/m/Y H:i',
  mask: true,
  step: 30,
  showTimezone: true,
  timezone: "-0200"
});

有什么帮助吗? 预先感谢!

jquery timezone datetimepicker
3个回答
3
投票

这在文档中很难找到,但您可以在

O
中传递
format
来告诉插件传递 GMT 偏移量。

serviceDateTime.datetimepicker({
    lang: 'pt-BR',
    format: 'd/m/Y H:i O',
    mask: true,
    step: 30,
    showTimezone: true,
});

侦探工作就是要找到

https://xdsoft.net/jqplugins/datetimepicker/#use_other_date_parser

然后从那里https://github.com/kartik-v/php-date-formatter#features

然后按照http://php.net/manual/en/function.date.php并搜索页面

"Difference to Greenwich time (GMT) in hours"

1
投票

该插件只是用于为用户提供一个选择日期和时间的界面。

如果您担心显示会基于您的时区,请查看这是否有帮助:

使用 jQuery 日期选择器计算时区


1
投票

嘿,我劫持了 Javascript 中的日期,强制我的客户使用 UTC/GMT 时间,并与 datetimepicker 一起使用

var daysInMonth     = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var daysInWeek      = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
var daysInWeekLong  = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var months          = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
var monthsShort     = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
var dateReg         = new RegExp("^(\\d{4})(\\d{2})(\\d{2})$");
var dateTimeReg     = new RegExp("^(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{0,2})$");
var timeReg         = new RegExp("^(\\d{2})(\\d{2})\\d{0,2}$");

function twoDigit(d) {
   return (d < 10 ? "0" + d : "" + d);
}

Date.prototype.format = function(f) {
   var day         = twoDigit(this.getDate()); 
   var dayWeek     = daysInWeek[this.getDay()]; 
   var dayWeekLong = daysInWeekLong[this.getDay()]; 
   var month       = twoDigit(this.getMonth() + 1); 
   var yearLong    = twoDigit(this.getFullYear()); 
   var yearShort   = twoDigit(this.getFullYear().toString().substring(3,4));
   var year        = (f.indexOf("yyyy") > -1 ? yearLong: yearShort);
   var hour24      = this.getHours(); 
   var hour_am_pm  = twoDigit((hour24 > 12 ? hour24 - 12 : hour24));
   var am_pm       = (hour24 >= 12 ? "PM" : "AM");
   var hour24      = twoDigit(hour24);
   var minute      = twoDigit(this.getMinutes()); 
   var second      = twoDigit(this.getSeconds()); 
   var monthShort  = monthsShort[this.getMonth()]; 
   var monthLong   = months[this.getMonth()]; 

   var dateString  = f.replace(/month/ig, monthLong).replace(/mon/ig, monthShort).replace(/dd/ig, day).replace(/dy/ig, dayWeek).replace(/day/ig, dayWeekLong).replace(/mm/ig, month).replace(/y{2,4}/ig, year).replace(/hh24/ig, hour24).replace(/hh/ig, hour_am_pm).replace(/am_pm/ig, am_pm).replace(/mi/ig, minute).replace(/ss/ig, second);
   return dateString;
} 

var _f = function(item) {
   Date.prototype["get" + item] = Date.prototype["getUTC" + item];
   Date.prototype["set" + item] = Date.prototype["setUTC" + item];
}
var _d = ['Milliseconds', 'Seconds', 'Minutes', 'Hours', 'Date', 'Month', 'FullYear', 'Year', 'Day'];
_d.forEach(_f);

Date = class extends Date {
   constructor(...options) {
      if (options.length == 1 && options[0].constructor == Date) {
         if (!isNaN(options[0])) {
            super(options[0]);
         } else {
            super();
         }
      } else if (options.length > 0) {
         if (!isNaN(options[0])) {
            super(Date.UTC(...options));
         } else {
            super();
         }
      } else {
         super();
      }
   }
};
© www.soinside.com 2019 - 2024. All rights reserved.