Using JS to display the current time sample

Source: Internet
Author: User
Tags current time

  This article mainly introduces the use of JS to display the current time sample, here also use jquery, let it also be introduced into the page

The front page display     code is as follows: <span id= "Clock" style= "FONT-SIZE:14PX;" ></span>     JS script     code as follows: $ (document). Ready (function () {//The first showTime ();//The second type of Var clock = new Clock (); Clock.display ($ ("#clock")); });  //Display system current time processing the first method   function ShowTime () { var myarray = new Array (7);  var TD = new Date ();  m Yarray[0] = "Sunday";  MYARRAY[1] = "Monday";  MYARRAY[2] = "Tuesday";  MYARRAY[3] = "Wednesday";  MYARRAY[4] = "Thursday";  MYARRAY[5] = "Friday";  MYARRAY[6] = "Saturday";  weekday = Td.getday ();  var h = td.gethours ();  var m = td.getminutes ();  var s = td.getseconds ();  var hstr = h;  var MSTR = m;  var ISTR = s;  if (H <) {Hstr = "0" + H};  if (M <) {MSTR = "0" + m};  if (S <) {ISTR = "0" + s};  $ ("#clock"). InnerHTML (' Current time: ' + new Date (). tolocaledatestring () + "" + Myarray[weekday] + "" + Hstr + ":" + MSTR + ":" + ISTR);  settimeout (showTime, 1000);  //Display system current time processing the second method function Clock () {var date = new Date (); This.year=date.getfullyear (); This.month=date.getmon th () +1; This.date=date.getdate (); This.day=newarray ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday") [Date.getday ()]; This.hour=date.gethours () <10? " 0 "+date.gethours ():d ate.gethours (); This.minute=date.getminutes () <10? " 0 "+date.getminutes ():d ate.getminutes (); This.second=date.getseconds () <10? " 0 "+date.getseconds ():d ate.getseconds ();   This.tostring=function () {return "Now time is:" +this.year+ "year" +this.month+ "month" +this.date+ "Day" +this.hour+ ":" + This.minute+ ":" +this.second+ "" +this.day; };   This.tosimpledate=function () {returnthis.year+ "-" +this.month+ "-" +this.date;};   This.todetaildate=function () {returnthis.year+ "-+this.month+"-"+this.date+" "+this.hour+": "+this.minute+" : "+this.second;};   This.display=function (ele) {varclock=newclock (); ele.innerhtml=clock.tostring (); Window.settimeout (function () {clock.display (ele);},1000); }; }  

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.