JS converts the date Date object to the timestamp __js

Source: Internet
Author: User
Tags set time timestamp to date
Converts a Date object to a timestamp

The first method, using the number () method

				var newday = new Date ();
				Console.log (number (newday));
Returns the time stamp of the current time

The second approach is to use the Date Object Date.parse () method

				var newday = new Date ();
				Console.log (Date.parse (NewDay));

Also returns the timestamp of the current time

The third method is to escape with an escape character

var newday = +new Date ();
				Console.log (NewDay);


Comparing the two methods,

The first time stamp returned using the method of a numeric object is accurate to milliseconds, and the Date object's Date.parse () method is only accurate to the second, and the three digits are filled with 0, so the individual recommends the first


convert timestamp to date object

var newdate = new Date (timestamp);  Instantiate a Date object, pass the timestamp directly into it, and note that it must be 13-bit
Or
var Timestamp3 = 1403058804000;  Declare a timestamp
var newdate = new Date ();  Instantiates a Date object
newdate.settime (Timestamp3);//Set time for the date object to be timestamp



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.