Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a JavaScript date object from a JSON store?

I have following JSON response created by Doctrine 2 as a datetime entity in server-side and encoded as JSON by zend framework`s Zend_Json::encode($stores) method:

{
"birthdate":
{"date":"2011-08-19 00:00:00","timezone_type":3,"timezone":"Europe\/Berlin"}
}

I need to create a new Date() using this JSON for my Extjs data grid but I can't figure out how to manipulate JSON response. Assuming I have a JSON store and I can access to birthdate object, new Date(birthdate.date) gives "Date {Invalid Date}".new Date("date":"2011-08-19 00:00:00") gives the same error but new Date("date":"2011-08-19") works fine. Please advice me on how to create a date object from my JSON store.

like image 875
Mehdi Fanai Avatar asked Jun 17 '26 08:06

Mehdi Fanai


1 Answers

You can parse the date using the following code

Date.parseDate("2011-08-19 00:00:00", "Y-m-d h:i:s");

API Doc

As per ExtJS 4.0 the method is changed as parse

Ext.Date.parse("2011-08-19 00:00:00", "Y-m-d h:i:s")

API Doc

like image 143
Arun P Johny Avatar answered Jun 18 '26 21:06

Arun P Johny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!