JS timestamp turns into date format

Source: Internet
Author: User
Tags time and date
<span id="Label3"></p><pre class="best-text mb-10">Convert a timestamp to a date format:<br>A simple line of code<br>var date = new Date (timestamp); Get a Time object note: if the timestamp is uinx, remember to multiply at 1000. For example, PHP function time () to get the timestamp will be multiplied by 1000<br><br>/*----------below is a way to get time and date, and what kind of format you need to stitch it up----------*/<br>Date.getfullyear ();//get the full year (4-bit, 1970)<br>Date.getmonth ();//get Month (0-11, 0 for January, Remember to add 1 when Using)<br>Date.getdate ();//acquisition Day (1-31)<br>Date.gettime ();//get time (number of milliseconds starting from 1970.1.1)<br>Date.gethours ();//acquisition of Hours (0-23)<br>Date.getminutes ();//get minutes (0-59)<br>Date.getseconds ();//get seconds (0-59)<br>More useful ways to find this http://www.w3school.com.cn/jsref/jsref_obj_date.asp<br><br>examples, such as the need for this format: yyyy-mm-dd hh:mm:ss<br>var date = new Date (1398250549490);<br>Y = date.getfullyear () + '-';<br>M = (date.getmonth () +1 < 10? ' 0 ' + (date.getmonth () +1): date.getmonth () +1) + '-';<br>D = date.getdate () + ";<br>H = date.gethours () + ': ';<br>m = date.getminutes () + ': ';<br>s = Date.getseconds ();<br>Console.log (y+m+d+h+m+s); yes, Hemp Disc.<br><br>Output: 2014-04-23 18:55:49<br><br>Convert a date format to a timestamp:<br>It's simple, Too.<br>Date = new Date (' 2014-04-23 18:55:49:123 '); Pass in a time format, if not passed is to get the current time, it is so simple.<br>There are three ways of getting<br>time1 = Date.gettime ()<br>Time2 = date.valueof ()<br>Time3 = Date.parse (Date)<br><br>Three ways to get the difference<br>first, second: Accurate to milliseconds<br>The third type: only accurate to the second, milliseconds will be replaced by the<br>For example, The result of the above code output (the difference can be seen at one glance):<br>1398250549123<br>1398250549123<br>1398250549000<br><br>Note: the time stamp obtained in addition to 1000 can get the Unix timestamp, which is used when the value is passed to Php.</pre><p><p>JS timestamp turns into date format</p></p></span>

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.