PDA

View Full Version : How to extract only the date from the Datefield object



cahello
8 Aug 2012, 1:16 PM
Hi,

I have an xtype datefield and timefield. On clicking a button, I am retrieving the values. The values, however, give information which I do not need. How can I convert these objects to string and manipulate accordingly?
For eg: the timefield returns some date, time and some text like (eastern standard time). I only want the time in hours and min and attach extra details myself.

Thanks

vietits
8 Aug 2012, 5:14 PM
Try this:


Ext.Date.format(timefield.getValue(), 'H:i:s');

8 Aug 2012, 6:19 PM
If you are using any server side code then you can convert your date like the one I have done it. You can specify the required format you want. Let me know if any doubt.
Java code :


SimpleDateFormat extJSDateFormat, requiredFormat = null;
Date date = null;
try {
extJSDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
System.out.println("Old date:" + oldDate);
// String oldDate = "2011-03-10T11:54:30.207Z";
date = extJSDateFormat.parse(oldDate.substring(0, 19));
requiredFormat = new SimpleDateFormat("MM/dd/yyyy");
System.out.println("OldDate:" + oldDate);
System.out.println("NewDate:" + requiredFormat.format(date));
} catch (Exception e) {
e.printStackTrace();
}


Thanks.
J.M.

cahello
9 Aug 2012, 6:59 AM
Thanks both of you. I tried this as suggested and it worked! :)



Ext.Date.format(timefield.getValue(), 'H:i:s');