Digital Clock (JavaScript, JQuery)

Source: Internet
Author: User

 

Javascript:

 

 

Function systemDate (){

// Obtain the system time

Var date = new Date (); www.2cto.com

Var month = date. getMonth () + 1; // month defaults to 0-11, so add 1

Var minutes = date. getMinutes (), Min;

Var seconds = date. getSeconds (), updateTime;

UpdateTime = 60-seconds;

Minutes <= 9? Min = "0" + minutes: Min = minutes;

Var week = date. getDay (), day;

Switch (week ){

Case 1: day = "Monday"; break;

Case 2: day = "Tuesday"; break;

Case 3: day = "Wednesday"; break;

Case 4: day = "Thursday"; break;

Case 5: day = "Friday"; break;

Case 6: day = "Saturday"; break;

Case 7: day = "Sunday"; break;

}

Var time = date. getFullYear () + "/" + month + "/" + date. getDate () + "" + date. getHours () + ":" + Min + "" + day;

$ ("# UpdateTime"). text (time); // jquery

// Var container = document. getElementById ("updateTime ");

// Container. innerText = time; // javascript;

SetTimeout ('systemdate () ', updateTime * 1000); // scheduled request time

}

 

HTML

<Div id = "updateTime"> </div> // container for displaying the digital clock

You can set the container style (* ^__ ^ ...... Attach the one used in the project (note: the week is not displayed)

As follows:

From: html5

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.