Common methods of JS Date Object

Source: Internet
Author: User
Tags set time

Common methods of JS Date Object
Creating an Event Object
var now = new Date (); The current time is returned by default in the case of no reference
Get year
var y=now.getfullyear ();
Get month
var m=now.getmonth () +1;//returns 0-11
Get Day
var d= now.getdate ();
Get hours
var h =now.gethours ();
Get minutes
var i =now.getminutes ();
Get seconds
var s =now.getseconds ();
Get the day of the week
Var week =now.getday ();//0-6 0 for Sunday
var weeks=[' Day ', ' one ', ' two ', ' three ', ' four ', ' five ', ' six ';
Console.log (y+ "year" +m+ ' month ' +d+ ' Day ' +h+ ' when ' +i+ ' min ' +s+ ' s ' + ' Week ' +weeks[week]);//July 17, 2017 17:55 41 second Monday
var times =now.gettime ();//Get timestamp
All of the above methods get replaced with set example setFullYear () setmonth () is the set time object
If you set the month parameter Setmonth (13) More than the month, the year plus 1 and so on

Example: Calculate the day of the week after 50 days
Method 1:
Now.setdate (Now.getdate () +50);
Console.log (Weeks[now.getday ());
Method Two
var now = new Date ();
var mytime=new date (Now.getfullyear (), Now.getmonth (), now.getdate () +50);//Set the date and time of the month and then the day must be
Console.log (Weeks[mytime.getday ()))

Common methods of JS Date Object

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.