如何强制JQ UI DatePicker在给定时区而不是本地工作?
例如:美国/多伦多
最佳答案
我们可以用 momentJS 解决这个提议+ 设置默认日期选项 JQ UI DatePicker
//Set default timezone for all new momentJS instances
moment.tz.setDefault('America/Toronto');
//Today date and time in America/Toronto timezone correction
var setDate = moment();
//Set defaultDate in proper date format for datepicker
$(element).datepicker(
{
defaultDate:setDate.format('MM/DD/YYYY')
}
记住:不要调用 toDate() 方法,使用 format() 来获取给定时区的正确日期和时间结果。
关于javascript - JQ UI DatePicker - 时区,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38783707/