-1

I'm developing a Calendar app on Phonegap using CalenStyle API, it accents events as JSON which is being fetched from Webservice. But When I parse the data to JSON, it's converting my date to GMT which is unrecognized by the API.

[{ "identifier": "255", "isAllDay":"false", "start": "9-4-2015 23:45", "end": "9-4-2015 23:45", "title":"Father's Day", "description": "Touchstone Preschool", "color": "#ff851b" }]

Above is the data I fetch from Webservice and format it for JSON Parsing. But as soon as I parse it using jQuery.parseJSON the date is getting converted to GMT as follows:

Object {identifier: "255", isAllDay: "false", start: Thu Apr 09 2015 00:00:00 GMT-0500 (Central Daylight Time), end: Thu Apr 09 2015 00:00:00 GMT-0500 (Central Daylight Time), title: "Father's Day"…}

So, "Thu Apr 09 2015 00:00:00 GMT-0500 (Central Daylight Time)" is not recognized by the API.

Snapshot of the console

Please tell me how can I prevent this from happening.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Please note that questions that beg for urgency [are not well received by the community here](http://meta.stackoverflow.com/q/326569/472495) - we ask that this request is omitted from questions, since it is not a good way to address volunteers. Thanks! – halfer Jul 25 '16 at 12:26
  • Sure @halfer, will follow it! – Abhilash Raj Jul 26 '16 at 03:12

1 Answers1

0

JSON itself does not specify how dates should be represented, but JavaScript does.

You should use the format emitted by Date's toJSON method:

2012-04-23T18:25:43.511Z

You can covert that format back to d-MMM-yyyy HH:mm

Use this library to convert it: Current time formatting with Javascript

  • Hello Wouter, Is there a way to retain the date as a string? i.e., `"start": "9-4-2015 23:45"` and just prevent it from getting converted into `start: Thu Apr 09 2015 00:00:00 GMT-0500 (Central Daylight Time)`. Any straight forward way to do this? – Abhilash Raj Jul 26 '16 at 03:17