A simple example of a JavaScript implementation page displaying current times in real time

Source: Internet
Author: User
Tags date current time
This article describes the page real-time display of the current time of a simple example, the need for friends can refer to the need copy code code as follows:


<title>javascript Implementation page Live display current time </title>
& lt;body>
<script language= "javascript" >
function Showtime ()
{
var today,hour,second,minute,y Ear,month,date;
Var strdate;
Today=new Date ();
var n_day = Today.getday ();
Switch (n_day)
{
Case 0:{
strdate = "Sunday"
}break;
Case 1:{
strdate = "Monday"
}break;
Case 2:{
strdate = "Tuesday"
}break;
Case 3:{
strdate = "Wednesday"
}break;
Case 4:{
strdate = "Thursday"
}break;
Case 5:{
strdate = "Friday"
}break;
Case 6:{
strdate = "Saturday"
}break;
Case 7:{
strdate = "Sunday"
}break;
}
Year = Today.getyear ();
Month = Today.getmonth () +1;
Date = Today.getdate ();
Hour = today.gethours ();
minute =today.getminutes ();
Second = Today.getseconds ();
if (month<10) month= "0" +month;
if (date<10) date=0 "+date;
if (hour<10) hour= "0" +hour;
if (minute<10) minute= "0" +minute;
if (second<10) second= "0" +second;
document.getElementById (' time '). InnerHTML = years + "Year" + Month + "Month" + Date + "Day" + strdate + "" + Hour + ":" + minu Te + ":" + second; Displays the time
settimeout ("Showtime ();", 1000);//Set function Auto Execution time for 1000 ms (1 s)
}
</script>
<div id= "Times" & Gt;</div>
<script language= "JavaScript" > Showtime (); </script>
</body>

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.