Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does ExtJS subtract a day when formatting a date?

Tags:

date

extjs4

Using ExtJS 4.0.2, I can type the following into the console:

Ext.util.Format.date('2012-01-13', "m-d-Y");

I get 01-12-2012

Why?
I can correct it with:

Ext.util.Format.date('2012-01-13 00:00:00', "m-d-Y");
like image 347
cbmeeks Avatar asked Nov 05 '22 07:11

cbmeeks


1 Answers

Ext.util.Format.date in Ext 4.0.2 uses a Date object or a String (your case). This string is parsed using the native Date.parse() using the UTC time zone.

Try to explicitly parse it using Ext.Date.parse:

var dt = Ext.Date.parse("2012-01-13", "Y-m-d");
Ext.util.Format.date(dt, "m-d-Y");
like image 193
Gregor Avatar answered Nov 10 '22 19:11

Gregor