Reputation: 11166
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
}
Upvotes: 3
Views: 6344
Reputation:
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.
Upvotes: 3
Reputation: 4343
I will take the commentor'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
Upvotes: 4