Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date in Parse REST API

I have a field in my Parse object set as Date. The object also has automatically added fields createdAt, updatedAt.

The response from the REST API looks like this

{"results":[
  {
    "createdAt":"2015-07-22T08:50:29.890Z",
    "updatedAt":"2015-07-22T08:50:29.890Z",
    "startDate":{"__type":"Date","iso":"2015-08-04T14:00:00.000Z"}
  }
]}

All three fields are of type Date. However, their representation varies and it breaks the serializer.

I also noticed that they behave differently in the data browser.

Is this by design or am I doing something wrong?

like image 642
Denzo Avatar asked Jul 17 '26 10:07

Denzo


1 Answers

"startDate": {
    "__type": "Date",
    "iso": "2015-08-04T14:00:00.000Z"
}

The above format is ISO date format. Parse supports ISO and all JS date formats (like the other ones). While we send data to Parse, it expects the date to be in ISO format.

You can parse the ISO date into JS format like this:

var startDate = new Date(results.startDate.iso);
like image 142
Yedhu Krishnan Avatar answered Jul 19 '26 13:07

Yedhu Krishnan