Java tips and tricks from a lady trying to play with the boys...

Thursday, March 15, 2012

ExtJS dateFormat Milliseconds

I am creating a page where I am using java.sql.Timestamp to keep track of when a record is updated. When displaying this on a grid, I was finding that the dateformat was failing when trying to display this data in a grid. I was passing the values to the page using JSON, and the date looked like this:
2012-03-14 17:22:31.809
I was unable to find how to format this particular date, since nearly all documentation of dates gives an example of a time without milliseconds. The API documentation states:
 u     Decimal fraction of a second                                              
Examples:
(minimum 1 digit, arbitrary number of digits allowed)         001 (i.e. 0.001s) or
100 (i.e. 0.100s) or
99 (i.e. 0.999s) or
999876543210 (i.e. 0.999876543210s)
 
Nope, this didn't work.

After searching around and trying nearly every letter in the alphabet, it turns out that you need to use ms for milliseconds. Your Date format should look like this:
Y-m-d H:i:s.ms
Hope this helps someone else!!