extJS或sencha中的日期时间转换

时间:2017-04-20 08:41:01

标签: extjs

你好,我想转换 03-04-2017 12:00 AM到2017-12-01 12:00:00 我怎么能在Ext Js中做到这一点 目前我的代码是:

 this.ToDatePicker = Ext.create('Ext.form.field.Text', {
        xtype: 'textfield',
        name: 'name',
        labelAlign: 'top',
        fieldLabel: 'Date Time',
        value: Ext.Date.format(new Date(), "d-m-Y h:iA"),
        listeners: {
            scope: this,
            afterrender: function (c) {
                c.getEl().on('click', function (e) {
                    console.log(e.target)
                    NewCssCal_DisableAfterToday(Ext.get(e.target).dom.id, 'ddmmyyyy', 'dropdown', true, 12)
                });
            }
        }
    });

this.ToCalenderIcon = new Ext.Container({
        html: "<img class='calIcons' src='public/touchWorldCssJs/images/cal.gif'/>",
        scope: this,
        padding: '27 5 5 5',
        listeners: {
            scope: this,
            afterrender: function (c) {
                c.getEl().on('click', function (e) {
                    if (Ext.get(e.target).hasCls('calIcons')) {
                        console.log(Ext.get(e.target).dom.id);
                        NewCssCal_DisableAfterToday(me.ToDatePicker.inputEl.id, 'ddmmyyyy', 'dropdown', true, 12)
                    }
                });
            }
        }
    });

this.ToCalenderIcon 渲染此设置日期格式后 03-04-2017 12:00 AM 所以我需要将此转换为2017-12-01 12:00 :00

1 个答案:

答案 0 :(得分:1)

据我所知,本地JavaScript不支持AM / PM概念,所以你必须通过Ext.Date按照指定的格式进行解析。

在你的toDatePicker中,你明确地将日期格式化为“d-m-Y h:iA”。 要将其恢复为不同的格式,您需要先解析它(因为JavaScript的本机日期无法解析生成的字符串):

Ext.Date.format(Ext.Date.parse("03-04-2017 12:00AM", "d-m-Y h:iA"), "d-m-Y h:i:s")

我希望这就是你要找的东西。 如果你有兴趣如何使4月3日看起来像12月1日,你应该首先写12月1日。