Date Object-current system time. Instance

Source: Internet
Author: User

The Date object is used to process dates and times.

Syntax for creating a Date object: var mydate=new date ()

Note: The Date object automatically saves the current date and time as its initial value.

The instance code is as follows:

Create an array to output the name of the week and month, for example:

<script type= "Text/javascript" >var d=new Date () var month=new Array (a) month[0]= "January" month[1]= "February" month[2]= "March" month[3]= "April" month[4]= "may" month[5]= "June" month[6]= "July" month[7]= "August" month[8]= " September "month[9]=" October "month[10]=" November "month[11]=" December "document.write (" the Month is "+ month[ D.getmonth ()])  //output: The month is February </script>

Common methods for date objects:

Date (): Returns the day and time

GetDate (): Returns a day in one months from a Date object (1~31)

GetDay (): Returns a day of the week from a Date object (0~6)

GetMonth (): Returns the month from the Date object (0~11)

getFullYear (): Returns the year from a date object with four-digit numbers

GetHours (): Returns the hour of the Date object (0~23)

Getminutes (): Returns the minute of the Date object (0~59)

Getseconds (): Returns the number of seconds of the Date object (0~59)

Getmilliseconds (): Returns the milliseconds of the Date object (0~999)

Date Object-current system time. Instance

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.