admin管理员组文章数量:1332345
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"));
版权声明:本文标题:typescript - How to convert an ISO 8601 date to 'Date(1525687010053)' format in javascript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742325367a2453616.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论