Sample Code for converting time from millisecond to date in js

Source: Internet
Author: User
This article mainly introduces the sample code of converting time from millisecond to datetime in js. For more information, see, I hope this will help you to convert the js Millisecond Time To the date time.

Var oldTime = (new Date ("20:10:10"). getTime (); // get the number of milliseconds

In most cases, we divide the number of milliseconds by 365*24*60*60*60 & 1000. This conversion method is too complicated. We need to obtain different methods, such as year, month, day, and hour, minute, and second, in addition, some years have 366 days and some 365 days, which is too complicated.

I tried a method later and succeeded.

Var oldTime = (new Date ("20:10:10"). getTime (); // get the number of milliseconds var newTime = new Date (oldTime); // get the normal time

You can directly input the number of milliseconds as the parameter to get the normal time for the Date object. Then, you can use getHours, getFullYear, and other methods to get the year, month, day, and hour, minute, and second.

Related Articles:

PHP converts seconds to days, hours, and minutes

PHP converts seconds to days, hours, and minutes.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.