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);
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);
Share
Improve this question
edited May 10, 2018 at 16:42
John Slegers
47.1k23 gold badges204 silver badges173 bronze badges
asked May 8, 2018 at 7:54
Mohammad IrshadMohammad Irshad
1391 gold badge3 silver badges11 bronze badges
2
- Can you be a bit more specific? Are you trying to convert '9999-12-31T00:00:00Z' to a timestamp? – Ahsan Commented May 8, 2018 at 8:00
-
var foo = '/Date(' + (new Date('9999-12-31T00:00:00Z')).getTime() + ')/'
– Salman Arshad Commented May 8, 2018 at 8:17
3 Answers
Reset to default 4I 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()
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>
You can do your conversion in just three easy steps :
- Convert your ISO 8601 string to a Date object
- Use
getTime
to convert your Date object to a universal time timestamp - Wrap
"/Date("
and")/"
around your result
Demo
function convert(iso8601string) {
return "/Date(" + (new Date(iso8601string)).getTime() + ")/";
}
console.log(convert("2011-10-05T14:48:00.000Z"));
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742325367a4422640.html
评论列表(0条)