Native JavaScript implements Web page display date clock effect

Source: Internet
Author: User

Just touch JavaScript in the date built-in objects, thought these methods are too simple, the result of their own actual operation to write a clock effect is really the moment I got stuck, there are a few points to pay attention to. First look at the actual effect

To achieve such an effect

A certain day of the week, a few days, a few seconds.

Look at the code effect first

<script type= "text/javascript" >
Window.onload=function () {
Showdate ();
Countdown ();
}
function Showdate () {
var mydate=new Date ();
var year=mydate.getfullyear ();
The Var month=mydate.getmonth () +1;//month Range is 0月-November, so add a
var date=mydate.getdate ();
var day=mydate.getday ();
var hour=mydate.gethours ();
var minute=mydate.getminutes ();
var second=mydate.getseconds ();
var weekday=new Array (7);

weekday[0]= "Monday";
weekday[1]= "Tuesday";
weekday[2]= "Wednesday";
weekday[3]= "Thursday";
weekday[4]= "Friday";
weekday[5]= "Saturday";
weekday[6]= "Sunday";

document.getElementById ("showTime"). innerhtml=year+ ' +month+ ' month ' +date+ ' +weekday[day]+hour+ ' when ' +minute+ ' + second+ ' seconds ';

T=settimeout (' showdate () ', 500);
}

Note that the range of month objects provided by the system is 0 to 11, not 12, so var month=mydate.getmonth+1;

You must also set the SetTimeout function to enable dynamic refresh of the number of seconds on a Web page

Native JavaScript implements Web page display date clock effect

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.