How to create clock and print button in web page

SiteGround WordPress Hosting Promo Discount 60 OFF

Many people use clock at their website, so i have posted this article with sample code to create clock in html page.

You can use following example to create clock and print button n HTML page.

<!DOCTYPE html>
<title>Create Clock and Print Button</title>  
<script type="text/javascript">  
//This is done only to make the below JavaScript code compatible to XHTML. <![CDATA[ 
var timerID = null 
var RunningTimer = false  
function stopclock(){ 
RunningTimer = false 
function startclock(){ 
timerID = setInterval("showtime()",1) 
RunningTimer = true 
function showtime(){ 
var now = new Date() 
var hours = now.getHours() 
var minutes = now.getMinutes() 
var seconds = now.getSeconds() 
var mseconds = now.getMilliseconds() 
var timeValue = "" + ((hours > 12) ? hours - 12 : hours) 
timeValue += ((minutes < 10) ? ":0" : ":") + minutes 
timeValue += ((seconds < 10) ? ":0" : ":") + seconds 
timeValue += ((seconds < 10) ? ":0" : ":") + mseconds 

timeampm = (hours >= 12) ? " P.M." : " A.M." 
document.clock.faceforclock.value = timeValue 
document.clock.faceforAMPM.value = timeampm  
<body onload="startclock()">   
<h3>Clock and Print Button</h3>
<form name="clock" action="#">  
<input type ="text" name="faceforclock" size="10" value ="" />  
<input type="text" name="faceforAMPM" size="5" value ="" />   
<input onclick="window.print();return false;" type="button" value="Print" />

When you run the above code following result will display.

clock and print button

You can try this editor ( to check the above code.

I use SEMRush for Keyword Research & Boost Organic Traffic. Do You?

Highly recommended SEM & SEO Tool for overview of Traffic, Keywords, Backlinks and more. You can search your competitors URL to analyze keywords & crush your competition.

Get Free Blogging Tips & Technology updates in your Email !!!

Subscribe via RSS feed

The following two tabs change content below.
Anil Kumar
IT Blogger Tips focus on Blogging Tips, SEO Tips, Social Media, SQL Tips, PL/SQL Tips, Oracle DBA, Linux/Unix, Latest Technology, How Tos and Technical Solutions. You can find us on Facebook | Twitter |
Find on Google+

Siteground SALE
60% OFF SiteGround WordPress Hosting – $3.95/month (Exclusive Offer !!!)