How to get time new date () in JS

Source: Internet
Author: User

How to get time new date () in JS

Get Time:

var New Date (); // Get system Current time
Mydate.getyear ();//get Current year (2-bit)Mydate.getfullyear ();//Get the full year (4-bit, 1970-????)Mydate.getmonth ();//Get the current month (0-11, 0 for January)Mydate.getdate ();//get current day (1-31)Mydate.getday ();//get Current week x (0-6, 0 for Sunday)Mydate.gettime ();//Gets the current time (the number of milliseconds since 1970.1.1)Mydate.gethours ();//gets the current number of hours (0-23)Mydate.getminutes ();//gets the current number of minutes (0-59)Mydate.getseconds ();//gets the current number of seconds (0-59)Mydate.getmilliseconds ();//gets the current number of milliseconds (0-999)Mydate.tolocaledatestring ();//Get Current datevarMytime=mydate.tolocaletimestring ();//Get current TimeMydate.tolocalestring ();//get date and time

JS Gets the current timestamp method

JavaScript gets the current timestamp:
The first method:

var timestamp =date.parse (new Date ());

Results found: 1280977330000 Note: The results obtained here convert the latter three bits (milliseconds) to 000 display, which may cause problems when used. For example, when adding the page element ID dynamically, it is not recommended.

The second method:

var timestamp = (new Date ()). ValueOf ();

Results: 1280977330748

The third method:

var timestamp=New Date (). GetTime ();

Results: 1280977330748

JS, call the new date () Separately, for example document.write (new Date ());

Displaying the result: Mar 10:10:43 utc+0800 2012 time in this format

However, using the new Date () Participation calculation is automatically converted to the number of milliseconds starting from 1970.1.1.

How to get time new date () in JS

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.