Js converts timestamp to date format

Source: Internet
Author: User
Tags timestamp to date

Js converts timestamp to date format
// Simple code var date = new Date (timestamp); // get a time object Note: if it is a uinx timestamp, remember to multiply it by 1000. For example, the timestamp obtained by the php function time () must be multiplied by 1000/* ---------- the following is the method for obtaining the time and date. You can just splice the time formats ---------- */date. getFullYear (); // obtain the complete year (4 bits, 1970) date. getMonth (); // obtain the month (0-11, 0 represents January, remember to add 1) date. getDate (); // get the date (1-31. getTime (); // obtain the time (number starting from 1970.1.1) date. getHours (); // obtain the hour (0-23) date. getMinutes (); // get the number of minutes (0-59) date. getSeconds (); // obtain the number of seconds (0-59) // more useful methods can be found here-> // example, for example, the following format is required: yyyy-MM-dd hh: mm: ssvar date = new Date (139825054949) 0); Y = date. getFullYear () + '-'; M = (date. getMonth () + 1 <10? '0' + (date. getMonth () + 1): date. getMonth () + 1) + '-'; D = date. getDate () + ''; h = date. getHours () + ':'; m = date. getMinutes () + ':'; s = date. getSeconds (); console. log (Y + M + D + h + m + s); // Ah Ma dish // output result: 18:55:49 convert the date format to the timestamp: // It is also very simple date = new Date ('2017-04-23 18: 55: 49: 2014 '); // input a time format, if it is not passed in, the current time is obtained. // You can obtain time1 = date in three ways. getTime () time2 = date. valueOf () time3 = Date. parse (date) // the difference between the first and second types: accurate to the third type: accurate to seconds, 0 will be used to replace // The output result of the above Code (the difference can be seen at a Glance): // 1398250549123 // 1398250549123 // 1398250549000

Related Article

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.