PDA

View Full Version : Date with Time extjs 3.4



neeraj.benjwal
10 May 2012, 2:34 AM
Is there any field which is used to display Date and time in same field.
i am not able to set the value of datefield with time using following code
--------------------------------------------------
i am using the following function for system date
--------------------------------------------------
function SystemTime(){
var mytime = "";
var suffix = "AM";
var currentTime = new Date();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
if (hours < 10){
hours = "0" + hours;
}
if (minutes < 10){
minutes = "0" + minutes;
}
if (hours >= 12) {
suffix = "PM";
hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}
mytime =hours +":"+ minutes +" "+ suffix;
return mytime;
}
-------------------------------------------------------------------
Extjs code is following
-------------------------------------------------------------------
new Ext.form.DateField({
id : 'sharedReleaseDate',
name : 'sharedReleaseDate',
fieldLabel : 'From<span style="color:red">*</span>',
format : 'm/d/Y', // DD/MM/YYYY
width : 150,
editable : true,
allowBlank : false,
listeners :{
select : function(){
var tdate = Ext.getCmp('sharedReleaseDate').getRawValue();
var systime = SystemTime();
var dateTime = tdate+' '+systime;
Ext.getCmp('sharedReleaseDate').setValue(dateTime);
}
}
}),

Thanks and Regards
Benjwal Neeraj

sword-it
10 May 2012, 2:57 AM
Hi,
I think this xtype: 'datefield' can also solve your problem. What you need to do, is the use of correct format with datefield to show the date with time in datefield.


{
xtype: 'datefield'
, width: 200
, format: 'm/d/Y g:i a' // the format of date with time.
, value: new Date()
}


You can choose your date time format from the below link also:
http://docs.sencha.com/ext-js/3-4/#!/api/Date

I think this will solve your problem.
Thanks.

team.avesta
28 Aug 2012, 3:10 AM
Thanks Dis really helped..!!! :)
=D>