Reputation: 139
How can I convert a date value formatted as 9999-12-31T00:00:00Z
to /Date(1525687010053)/
format in javascript?
I have this, but it doesn't work:
var datevalue = '9999-12-31T00:00:00Z';
var converteddate = Date.parseDate(datevalue);
Upvotes: 1
Views: 10868
Reputation: 47101
You can do your conversion in just three easy steps :
getTime
to convert your Date object to a universal time timestamp"/Date("
and ")/"
around your resultfunction convert(iso8601string) {
return "/Date(" + (new Date(iso8601string)).getTime() + ")/";
}
console.log(convert("2011-10-05T14:48:00.000Z"));
Upvotes: 0
Reputation: 79
I assume that you want to get the timestamp of that date. This can be achieved with the code below
var timestamp = new Date('9999-12-31T00:00:00Z').getTime()
Upvotes: 4
Reputation: 649
I don't understand your question, but your code is wrong. There is no Date.parseDate()
function in javascript, only Date.parse()
:
var datevalue = '9999-12-31T00:00:00Z';
var converteddate = Date.parse(datevalue);
document.getElementById('result').innerHTML = converteddate;
console.log(converteddate)
<p id="result"></p>
Upvotes: 1