Javascript to display client date and time on webpage

By: pmprash@yahoo.co.in Emailed: 1614 times Printed: 2079 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

Use below code to display client date and time on web page. <HTML><HEAD><TITLE></TITLE>
<META http-equiv=Content-Type content=\"text/html; charset=iso-8859-1\">
<STYLE type=text/css>.mainheading {     FONT-WEIGHT: bold; FONT-SIZE: 14px; COLOR: #000000; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif }.mainbody {     FONT-SIZE: x-small; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; LIST-STYLE-TYPE: square}.maintitle { FONT-WEIGHT: bold; FONT-SIZE: medium; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif}</STYLE>
</HEAD>
<BODY text=#000000 bgColor=#ffffff leftMargin=1 topMargin=0 onload=\"setFromTo();\">
<TABLE cellSpacing=3 cellPadding=0 width=770 border=0>
 <TBODY>
 <TR>
   <TD width=77>&nbsp;</TD>
   <TD class=mainheading>
     <P>&nbsp;</P>

   </TD>
 </TR>
 <TR>
   <TD colSpan=2>
     <HR color=green>
   </TD>
 </TR>
 <TR>
   <TD width=77>&nbsp;</TD>
   <TD><P></P>
<P>Today\'s Date & Time on Client machine </P>
<SCRIPT LANGUAGE=\"JavaScript\">
<!--
tday  =new Array(\"Sun\",\"Mon\",\"Tue\", \"Wed\",\"Thu\",\"Fri\",\"Sat\ ");
tmonth=new Array(\"January\",\"February\" ,\"March\",\"April\",\"May\",\ "June\",\"July\",\"August\",\" September\",\"October\",\" November\",\"December\");
function GetClock(){
d = new Date();
nday   = d.getDay();
nmonth = d.getMonth();
ndate  = d.getDate();
nyeara = d.getYear();
nhour  = d.getHours();
nmin   = d.getMinutes();
nsec   = d.getSeconds();
if(nyeara<1000){nyeara=(\"\"+( nyeara+11900)).substring(1,5); }
else{nyeara=(\"\"+(nyeara+ 10000)).substring(1,5);}
    if(nhour ==  0) {ap = \" AM\";nhour = 12;}
else if(nhour <= 11) {ap = \" AM\";}
else if(nhour == 12) {ap = \" PM\";}
else if(nhour >= 13) {ap = \" PM\";nhour -= 12;}
if(nmin <= 9) {nmin = \"0\" +nmin;}
if(nsec <= 9) {nsec = \"0\" +nsec;}
document.getElementById(\' clockbox\').innerHTML=\"\"+ tday[nday]+\", \"+tmonth[nmonth]+\" \"+ndate+\", \"+nyeara+\" \"+nhour+\":\"+nmin+\":\"+ nsec+ap+\"\";
setTimeout(\"GetClock()\", 1000);
}
window.onload=function(){ GetClock();}
//--></script>
<div id=\"clockbox\"></div>
<P></P>
<P> Admin</P>
  <P class=mainbody>&nbsp;</P>
   </TD>
 </TR>
 <TR>
   <TD width=77>&nbsp;</TD>
   <TD class=mainbody></TD>

 </TR>
 <TR>
   <TD colSpan=2>
     <HR color=green>
   </TD>
 </TR>
 </TBODY>
</TABLE>
</BODY>
</HTML>


Javascript Home | All Javascript Tutorials | Latest Javascript Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by pmprash@yahoo.co.in
Javascript to display client date and time on webpage

More Tutorials in Javascript
Use WinSCP to transfer log files remotely using Javascript
Verifying user input in JavaScript
Pause execution in JavaScript
Javascript to display client date and time on webpage
Getting Browser's height and width using Javascript
Highlighting text on a page using CSS
Using revealTrans to do page transitions in Javascript
Password protect a web page using Javascript
Diabling Right Click option in a browser using Javascript
Scrolling message on the status bar using Javascript
window.frames[i] in Javascript
Form validation using Javascript
Using && in Javascript
The if statement in Javascript
do-while, while, for and for-in loops in Javascript

More Latest News
Most Viewed Articles (in Javascript )
Typecasting in Javascript
Show how many characters remaining in a html text box using javascript
List of Keywords and reverved words in Javascript
Using toString() in JavaScript to convert data types to String
Bitwise NOT, AND, OR, XOR operators in Javascript
Form validation using Javascript
Javascript to display client date and time on webpage
Click to remove an element from a select html form using javascript
History and evolution of Javascript
Javascript Basics
Using parseInt() and parseFloat() in JavaScript to convert data types to Numbers
Using ! and !! in Javascript
Using && in Javascript
The if statement in Javascript
do-while, while, for and for-in loops in Javascript
Most Emailed Articles (in Javascript)
Getting Browser's height and width using Javascript
Javascript to display client date and time on webpage
Click to remove an element from a select html form using javascript
List of Keywords and reverved words in Javascript
Pause execution in JavaScript
Using parseInt() and parseFloat() in JavaScript to convert data types to Numbers
switch in Javascript
window.frames[i] in Javascript
Show how many characters remaining in a html text box using javascript
History and evolution of Javascript
Javascript Basics
Use WinSCP to transfer log files remotely using Javascript
Typecasting in Javascript
Using ! and !! in Javascript
do-while, while, for and for-in loops in Javascript