PDA

View Full Version : MySql timestamp parsing question



jnicora
5 Nov 2009, 1:57 PM
Hoping this is an easy answer. I am using Java to get a result set from MySql. In this result set is a field of data type timestamp. In my routine to convert the result set to JSON data, the timestamp output this "2009-11-06 09:51:45.527". This is the standard MySql timestamp format (year-month-day hour-minute-second.millisecond). Look at the following code, the timestamp WITH milliseconds does not parse, however, if you remove the decimal, it parses fine. Is this a bug? Or does Extjs expect the middle-ware to truncate milliseconds?



dt1 = Date.parseDate("2006-01-15 3:20:01 PM", "Y-m-d g:i:s A");
dt2 = Date.parseDate("2009-11-06 09:51:45.527", "Y-m-d g:i:s A");
console.log(dt1,dt2);


Thanks in advance!

jergarmar
5 Nov 2009, 2:23 PM
dt2 = Date.parseDate("2009-11-06 09:51:45.527", "Y-m-d H:i:s.u");

Gotta get the format exact to work properly.

jnicora
5 Nov 2009, 2:36 PM
dt2 = Date.parseDate("2009-11-06 09:51:45.527", "Y-m-d H:i:s.u");
Gotta get the format exact to work properly.

Ah yes, I didn't think my example through, consider this case instead.

Here is my store config:



schema = {
fields: [{
header: "Column 1",
dataIndex: "col1",
type: "date",
format: "Y-m-d g:i:s A"
}],
data: [["2009-11-06 09:51:45.527"]]
};


The data is a direct output of a timestamp field from the JDBC driver from a MySql database. I am trying to avoid any middle-ware or database formatting and just handle it on the client. The problem is that Extjs does not display any data for that field, if I hard code the date value to "2009-11-06 09:51:45" then it displays with the proper formatting. I was hoping that Ext would see it's a date type, parse it, then format that date object accordingly, and it does when I remove the decimal, however, unless I cast that value on the database end (do not want), that value will reach the client with a decimal.

evant
5 Nov 2009, 2:51 PM
You need to use dateFormat, not format.

jnicora
5 Nov 2009, 3:22 PM
******edit, ignore this. I missed what evant was saying, his change got it working, sorry for the confusion and thanks for the help as always =)


You need to use dateFormat, not format.