I am trying to send UTC time-stamp to rest service from my javascript client. i was not able to create time-stamp like "2013-08-30T19:52:28.226Z"
using javascript.
var rawDate = date.getUTCDate().toString();
i see this example but not helpful for me. utc-time-stame-javascript
You can use date.toJSON()
.
new Date().toJSON()
"2013-08-31T09:05:07.740Z"
See MDN or MSDN
1) Get the date.
var now = new Date();
2) Convert to UTC format like below, for reference.
var now_utc = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(),
now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());
3) Using toJSON, get the format.
now_utc.toJSON()
Finally,
var now = new Date();
var now_utc = new Date(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), now.getUTCMinutes(), now.getUTCSeconds());
alert(now_utc.toJSON());
Check this JSFiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With