I'm using DateTime to create Date objects and sending them to UI as JSON. How can I use that in JavaScript (Angular JS) and convert it back and forth.
Example: If I want to get the user update the time, I should be able to get the Date/Time from a form submission and send it back to the Server in json.
Here is my current DateTime json output that the client recives
"date": {
"year": 2013,
"era": 1,
"dayOfMonth": 3,
"dayOfWeek": 7,
"dayOfYear": 34,
"millisOfDay": 3660000,
"centuryOfEra": 20,
"yearOfCentury": 13,
"monthOfYear": 2,
"weekOfWeekyear": 5,
"millisOfSecond": 0,
"hourOfDay": 1,
"yearOfEra": 2013,
"weekyear": 2013,
"secondOfMinute": 0,
"secondOfDay": 3660,
"minuteOfHour": 1,
"minuteOfDay": 61,
"zone": {
"fixed": true,
"id": "UTC"
},
"millis": 1359853260000,
"chronology": {
"zone": {
"fixed": true,
"id": "UTC"
}
},
"beforeNow": true,
"afterNow": false,
"equalNow": false
}
I'm using DateTime to create Date objects and sending them to UI as JSON. How can I use that in JavaScript (Angular JS) and convert it back and forth.
Example: If I want to get the user update the time, I should be able to get the Date/Time from a form submission and send it back to the Server in json.
Here is my current DateTime json output that the client recives
"date": {
"year": 2013,
"era": 1,
"dayOfMonth": 3,
"dayOfWeek": 7,
"dayOfYear": 34,
"millisOfDay": 3660000,
"centuryOfEra": 20,
"yearOfCentury": 13,
"monthOfYear": 2,
"weekOfWeekyear": 5,
"millisOfSecond": 0,
"hourOfDay": 1,
"yearOfEra": 2013,
"weekyear": 2013,
"secondOfMinute": 0,
"secondOfDay": 3660,
"minuteOfHour": 1,
"minuteOfDay": 61,
"zone": {
"fixed": true,
"id": "UTC"
},
"millis": 1359853260000,
"chronology": {
"zone": {
"fixed": true,
"id": "UTC"
}
},
"beforeNow": true,
"afterNow": false,
"equalNow": false
}
Share
Improve this question
edited Aug 8, 2013 at 13:58
Gray
117k24 gold badges302 silver badges359 bronze badges
asked May 27, 2013 at 16:45
user6123723user6123723
11.2k19 gold badges72 silver badges111 bronze badges
1
- 1 you don't have a timestamp ? – Ven Commented May 27, 2013 at 16:49
2 Answers
Reset to default 4I will take the mentor's question and recast it as an answer. Make sure your server outputs the date/time in a more simplified view such as a timestamp, just the milliseconds and either assume UTC or send that as well. I have solved it given your current message above, but it really is a waste, message should be more simple.
new Date(date.millis); gives you a javascript object with the time and date of Sat Feb 02 2013 19:01:00 GMT-0600 (Central Standard Time)
Central in my case.
Other post handles the UTC questions new Date().setUTCSeconds(date.millis); Convert UTC Epoch to local date with javascript
I would strongly suggest using ISO 8601 for your times. It includes the date and time, as per a timestamp, but also a timezone so that you have the additional information required to store and display it in the correct format for the user who submitted it. This is useful information to keep around if you have users in multiple timezones.