0

我使用 extjs 创建了一个简单的应用程序timefield。这是代码和小提琴

Ext.create('Ext.form.Panel', {
    title: 'Time Card',
    width: 300,
    bodyPadding: 10,
    renderTo: Ext.getBody(),
    items: [{
        xtype: 'timefield',
        id: 'in',
        fieldLabel: 'Time In',
        //minValue: '6:00 AM',
        //maxValue: '8:00 PM',
        format: 'H:i',
        increment: 30,
        anchor: '100%'
    }, {
        xtype: 'button',
        text: 'click',
        handler: function(){
           alert(Ext.getCmp('in').getValue());
           console.log(Ext.getCmp('in').getValue());
        }
   }]
});

问题/问题:

  1. 当我使用 getValue() 它返回Tue Jan 01 2008 01:00:00 GMT-0500 (Eastern Standard Time). 我不确定为什么它会返回 2008 年?
  2. 有没有办法捕获时区信息?
4

2 回答 2

0

timefield包含的来源

/**
 * @private
 * This is the date to use when generating time values in the absence of either minValue
 * or maxValue.  Using the current date causes DST issues on DST boundary dates, so this is an
 * arbitrary "safe" date that can be any date aside from DST boundary dates.
 */
initDate: '1/1/2008',
initDateParts: [2008, 0, 1],

您可以覆盖这些属性,尽管它们被标记为私有,但我不建议这样做。我建议使用日期字段和时间字段,然后从中计算日期和时间。

JavaScript 不支持时区,它们只支持 UTC 和 Local。ExtJS 也不支持时区。如果您需要任意时区,可以查看moment.js

于 2015-12-30T02:49:41.620 回答
0

renderer您可以通过执行类似于此的操作来获得正确的函数日期:

renderTimeField: function(time) {
    var ndate = new Date(),
        tmin = time.getMinutes(),
        thour = time.getHours();

    return new Date(ndate.setHours(thour, tmin, 0, 0));
},
于 2016-02-25T18:04:47.277 回答