Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How javascript turns time into milliseconds

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly introduces "how javascript turns time to milliseconds". In daily operation, I believe many people have doubts about how javascript turns time to milliseconds. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts of "how javascript turns time to milliseconds". Next, please follow the editor to study!

Javascript changes time to milliseconds: 1, through "(new Date (startDate)). GetTime ();" convert the date to milliseconds; 2, through "Date.parse (new Date (arr [0]...)". Method to convert the date to milliseconds.

This article operating environment: windows7 system, javascript1.8.5 version, Dell G3 computer.

How does javascript turn the time to milliseconds?

Date converted to millisecond

If the format is: yyyy/mm/dd hh:mm:ss can be converted directly. Var oldTime = (new Date ("14:13:11 on 2018-07-09"). GetTime (); / / get milliseconds

If the date format is: yyyy-mm-dd hh:mm:ss needs to convert the format

Var startDate= '2018-07-09 14 new RegExp 13 new RegExp 11; startDate= startDate.replace ("-", "gm"), "/"); var startDateM = (new Date (startDate)). GetTime (); / / get milliseconds

Another way to convert dates to milliseconds:

Var str = '2018-07-09 14-14-7-09 14-12-14-14-14-14-12-11) arr = str.split (/ [-:\ /] /); var startDate = Date.parse (arr [0], arr [1]-1, arr [2], arr [3], arr [4], arr [5]); console.log (startDate), this is the end of the study on "how javascript turns time in milliseconds", hoping to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report