admin管理员组文章数量:1336632
I have a date in the format yyyy-MM-ddTHH:mm:ss and I want to convert it to datetime format in such a way that if the result is evaluated via getTime() method, it will return number of milliseconds. For now, the method I have tried is throwing the error : Uncaught TypeError: dt.getTime is not a function where dt is the resultant date. Please state a way to achieve this using javascript.
Thanks in advance.
I have a date in the format yyyy-MM-ddTHH:mm:ss and I want to convert it to datetime format in such a way that if the result is evaluated via getTime() method, it will return number of milliseconds. For now, the method I have tried is throwing the error : Uncaught TypeError: dt.getTime is not a function where dt is the resultant date. Please state a way to achieve this using javascript.
Thanks in advance.
Share Improve this question asked Nov 9, 2016 at 11:36 AbhayAbhay 351 gold badge1 silver badge4 bronze badges 3-
I have a date in the format yyyy-MM-ddTHH:mm:ss
. Is it adate
orstring
? – Pugazh Commented Nov 9, 2016 at 11:41 - would you consider using MomentJS or not? – Marek Urbanowicz Commented Nov 9, 2016 at 11:42
- @Pugazh It is in string format @ Marek Urbanowicz If there is an option to achieve this without using MomentJS it would be better. Otherwise plz suggest the MomentJS way. – Abhay Commented Nov 9, 2016 at 11:45
1 Answer
Reset to default 4If your date is string, you should initialize new Date object with your time string as parameter. getTime() is method of Date object. Note that it may not work in all browsers.
var date = new Date('2016-11-09T18:00:01');
alert(date.getTime())
https://jsfiddle/rxo5zz71/
本文标签:
版权声明:本文标题:Convert the format yyyy-MM-ddTHH:mm:ss to datetime in javascript which is acceptable by getTime() function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742412865a2470138.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论