【问题标题】:ExtJS DateField using datetime formatExtJS DateField 使用日期时间格式
【发布时间】:2011-12-02 07:23:23
【问题描述】:
var todate = new Ext.form.DateField({
        format: 'd/m/Y', 
        fieldLabel: '',
        id: 'txtExpireDate',
        name: 'txtExpireDate',
        width: 150,
        allowBlank: false,
        value: '',
        renderTo: 'divDateExpire'
    });

此代码仅显示日期。如何使用日期时间格式?

谢谢

【问题讨论】:

  • 您说的是哪种日期时间格式?你必须让你的问题更清楚。

标签: datetime extjs format datefield


【解决方案1】:

Ext.Form.DateField 中,我们无法在日期选择器中选择日期时直接显示时间。为此我们添加了监听器:

var dtpIssueDate = new Ext.form.DateField({
  listeners: {
    select: function(dtpIssueDate, date) {
      BindTimeWithDate(date);
    }
  }
});

//Bind time with date selected in the picker
function BindTimeWithDate(date) {
  try {
    var currentTime = new Date()

    // Get a current hours and add with date.
    date.setHours(currentTime.getHours());

    // Get a current minutes and add with date.
    date.setMinutes(currentTime.getMinutes());

    dtDateTimeValue = date.format('dd/MM/yyyy HH:mm');
    dtpIssueDate.SetText(dtDateTimeValue); 
  }
  catch (e) {
    alert(e.message);
  }
}

【讨论】:

    【解决方案2】:

    extjs 库中没有可以同时显示日期和时间的组件。因此,您不能同时使用日期时间格式。最接近的是with this.

    希望这会有所帮助。

    【讨论】:

    • 我有这个问题的解决方案。按设置格式:'d/m/Y H:i:s'
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-06
    • 2014-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多