Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display time and date in extjs

Tags:

extjs

How can I display date/time in grid panel. The date is coming from server side asp.net web service as:

{9/14/2009 10:23:00 AM}

I am getting an error in displaying the date and time. It shows NaN/NaN/NaN 12:NaN:NaN PM

var store = new FMP.AspNetJsonStore({
            fields: [
                      { name: 'DateOccurred'}
                     ],
 });

var dateRenderer = Ext.util.Format.dateRenderer('m/d/Y h:i:s A');

 { header: xppo.st('SDE_DATE_OCCURRED'), width: 75, sortable: true,
     dataIndex: 'DateOccurred', renderer: dateRenderer },

In the store if I define fields:

[ { name: 'DateOccurred', type: 'date', dateFormat: 'm/d/Y'} ],

... it displays a blank field.

Please help me in this issue.

like image 430
xrx215 Avatar asked Jan 14 '10 18:01

xrx215


1 Answers

The specified dateFormat must match the date string exactly for it to parse. The format 'm/d/Y' fails because it is missing the time component and 'm' expects a 2 digit month. A dateFormat which successfully parses your example date string is:

'n/d/Y H:i:s A'

You can also try omitting dateFormat while leaving the field's type set to 'date'. In absence of a specific format ExtJS will fall back on Date.parse.

like image 101
owlness Avatar answered Sep 16 '22 15:09

owlness