Reputation: 429
I want to show current time on a window in my app which is written using Extjs. The time should be updated every one second but I don't know how to do it. this is my code: Can anyone help me please?
function gettime(){
var dt = new Date();
dt = dt.format('h:i:s');
return dt;
};
var clock = {
layout:'form',
frame:false,
region:'center',
height:100,
width:400,
items:[{
id: 'currtime',
xtype: 'displayfield',
fieldLabel: 'Current Time',
value:gettime()
}]
}
Upvotes: 1
Views: 324
Reputation: 3411
You can use TaskManager for that:
// Start a simple clock task that updates a div once per second
var task = {
run: function(){
Ext.fly('clock').update(new Date().format('g:i:s A'));
},
interval: 1000 //1 second
}
Ext.TaskMgr.start(task);
Upvotes: 1