JS implementation 12-hour clock

Source: Internet
Author: User
Tags apm

1<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">234<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>5<title> make 12-hour clock </title>6<script type= "Text/javascript" >7 8 functionclock_12h ()9 {Ten  varToday =NewDate ();//Get current Time One  //gets the year, month, day, month in the date () function is calculated from 0-11 A  varYear =today.getfullyear ();  -  varmonth = Today.getmonth () +1; -  varDate =today.getdate (); the  varhour = Today.gethours ();//get hours, minutes, seconds -  varminute =today.getminutes (); -  varSecond =today.getseconds (); -   +  varApm= "AM";//Show by default morning: AM -  if(HOUR&GT;12)//display by 12-hour system +  { AHour=hour-12; atApm= "PM"  ; -  } -  varWeekday = 0; -  Switch(Today.getday ()) { -      Case0: -Weekday = "Sunday"; in      Break; -      Case1: toWeekday = "Monday"; +      Break; -      Case2: theWeekday = "Tuesday"; *      Break; $      Case3:Panax NotoginsengWeekday = "Wednesday"; -      Break; the      Case4: +Weekday = "Thursday"; A      Break; the      Case5: +Weekday = "Friday"; -      Break; $      Case6: $Weekday = "Saturday"; -      Break; -  } the   -   /*set the content of the div to the current time*/Wuyidocument.getElementById ("Myclock"). innerhtml= "; the  - } Wu /*call CLOCK_12H () after specifying milliseconds per interval using setinterval ( )*/ - varMyTime = SetInterval ("clock_12h ()", 1000); About  $</script> - -  -<body> A<div id= "Myclock" ></div> +</body> the

JS implementation 12-hour clock

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.