I have dates stored using Parse backend. I retrieve them using JSON.stringify. Everything is working fantastic except for dates. I need to convert them to JavaScript dates. I understand that Parse stores dates in ISO 8601 format preceded by characters as in this example:
{"__type":"Date","iso":"2013-05-07T00:00:00.000Z"}
Could sure use some help on trying to convert above to standard JavaScript date. Thanks!
I have dates stored using Parse. backend. I retrieve them using JSON.stringify. Everything is working fantastic except for dates. I need to convert them to JavaScript dates. I understand that Parse. stores dates in ISO 8601 format preceded by characters as in this example:
{"__type":"Date","iso":"2013-05-07T00:00:00.000Z"}
Could sure use some help on trying to convert above to standard JavaScript date. Thanks!
Share asked Jun 6, 2013 at 22:26 hypermilerhypermiler 2,1074 gold badges21 silver badges27 bronze badges2 Answers
Reset to default 8The iso8601 isn't an issue: see JavaScript Date ISO8601
As for getting the item out, don't use JSON.stringify, just access the part you need:
var d = {"__type":"Date","iso":"2013-05-07T00:00:00.000Z"};
d = new Date(d.iso);
For those who dont know how to get the date and the time from an input (Works in chrome, opera and safari) HTML code
<input type="date" id="thedate">
<input type="time" id="thetime">
Javascript code
var a = document.getElementById("thedate").value;
var b = document.getElementById("thetime").value;
x = a + 'T' + b + '+02:00'; //the +02:00 is because i live in Greece and we are +02:00 GMT! Choose your own.
var d = {"__type":"Date","iso":x};
d = new Date(d.iso);
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745049705a4608311.html
评论列表(0条)