2017-10-10 31 views
0
Ext.application({ 
    name: 'Fiddle', 
    launch: function() { 
     var t1 = Ext.create('Ext.form.field.Time', { 
      xtype: 'timefield', 
      name: 'in', 
      fieldLabel: 'Time In', 
      minValue: '6:00 AM', 
      maxValue: '8:00 PM', 
      increment: 60, 
      renderTo: Ext.getBody() 
     }); 
     var time = Ext.Date.add(new Date(), Ext.Date.HOUR, + 14).getHours(); //getting hour values in 24 format want in 12 hours format 
     t1.setMaxValue(time); //unable to setMaxValue 
    } 
}); 
+0

這是你的第11個問題,其他人不得不重新格式化你的代碼在每一個他們,告訴你在改變,沒有興趣...... – Alexander

+0

什麼版本的ExtJS的這是什麼? – tommyO

回答

1

可以使用Ext.Date類用於獲取12小時格式。

這裏被無視一些格式: -

  1. 12小時一個小時的格式沒有前導零1至12
  2. 分鐘,用前導零00到59
  3. a小寫前綴meridiem和後期meridiem上午或下午
  4. 大寫安特meridiem和Post meridiem上午或下午

我已經創建了一個Sencha fiddle演示它顯示如何工作的。希望這會幫助你解決你的問題。

Ext.create('Ext.form.Panel', { 
    title: 'Time Card', 
    width: 300, 
    bodyPadding: 10, 
    renderTo: Ext.getBody(), 
    defaults: { 
     xtype: 'timefield', 
     minValue: '6:00 AM', 
     maxValue: '8:00 PM', 
     increment: 30, 
     anchor: '100%', 
     listeners: { 
      change: function (timefield, newValue) { 
       Ext.Msg.alert('Succes', 'Good you have selected <b>' + Ext.Date.format(newValue, 'g:i A') + '</b>'); 
      } 
     } 
    }, 
    items: [{ 
     name: 'in', 
     fieldLabel: 'Time In' 
    }, { 
     name: 'out', 
     fieldLabel: 'Time Out' 
    }, { 
     xtype: 'button', 
     text: 'Get current GMT+14 Time', 
     handler: function() { 
      var date = new Date(), 
       dateGmtPlus14 = new Date(date.valueOf() + date.getTimezoneOffset() * 60000); //Multiply this by 60,000 (milliseconds in a minute) to get the milliseconds and subtract from the date to create a new date 

      Ext.Msg.alert('Succes', 'Current time with GMT+14 is <br> 12 hours format : <b>' + Ext.Date.format(dateGmtPlus14, 'g:i:s A') + 
       '</b><br>24 hours format: <b> ' + Ext.Date.format(dateGmtPlus14, 'G:i:s') + '</b>'); 
     } 
    }] 
}); 

您可以使用Date.getTimezoneOffset()MDN。這會以分鐘爲單位返回您的日期和GMT之間的時差。

將其乘以60,000(毫秒一分鐘)以獲得毫秒並從日期中減去以創建新日期。

new Date(date.valueOf() + date.getTimezoneOffset() * 60000) 
+0

謝謝你爲我工作 – anka

+0

有無論如何得到當前格林尼治標準時間+14時間在extjs傳遞到時間字段 – anka

+0

意味着你想要從當前時間的下一個14小時的時間嗎? –

相關問題