Convert the format yyyy-MM-ddTHH:mm:ss to datetime in javascript which is acceptable by getTime() function - Stack Overflow

I have a date in the format yyyy-MM-ddTHH:mm:ss and I want to convert it to datetime format in such a w

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 a date or string ? – 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
Add a ment  | 

1 Answer 1

Reset to default 4

If 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/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742412865a4439164.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信