JS Simple Date Acquisition (Beginner Basics)

Source: Internet
Author: User
Tags define function

About JS Date acquisition to use the most basic date () method to get the date of the day

var d =new Date (); Defining Date Objects

var y=d.getfullyear (); Get year

var m=d.getmonth () +1; Returns the month (0 ~ 11) from the Date object, so add 1.

var dd=d.getdate (); Get Day

Get hours, minutes, and seconds in the same vein. Note: 1 seconds =1000 milliseconds

<! DOCTYPE html>#box {width:650px;height:80px;background: #ccc; Color:green;font-size:26px;text-align:center;line-height:80px;} </style> <script>window.onload=function(){        varObox=document.getelementbyid (' box '); functionShow () {//define function Show            varD =NewDate (); vary=d.getfullyear (); varM=d.getmonth (+1); varDd=d.getdate (); varH=d.gethours (); varmm=d.getminutes (); vars=d.getseconds (); vart=y+ "Year" +m+ "month" +dd+ "Day" +h+ "+mm+" minute "+s+" seconds "; Obox.innerhtml=t;//Use the date innerHTML in the Div} setinterval (show,1000);//Timer (1: Call Show 2:1 seconds =1000 milliseconds to refresh)Show ();//The call to show function is to press the F5 refresh when the screen does not appear to be interrupted.     }    </script>

JS Simple Date Acquisition (Beginner Basics)

Related Article

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.