HTML Tutorial


 Forum HomeForum Home   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
displaying the current time and date at the top of the page
Post new topic   Reply to topic    HTML Help Forum Index -> HTML Tools
View previous topic :: View next topic  
Author Message
angelprone



Joined: 05 Jul 2007
Posts: 15

PostPosted: Thu Jul 05, 2007 6:14 pm     displaying the current time and date at the top of the page Reply with quote

ei guys i need a sample code on how to display the current time and date at the top of the web page...i need your help...tnx
Pattons3rd



Joined: 28 Dec 2006
Posts: 1212
Location: Colorado

PostPosted: Fri Jul 06, 2007 3:34 am     Reply with quote

See post How to display the time
angelprone



Joined: 05 Jul 2007
Posts: 15

PostPosted: Mon Jul 09, 2007 10:21 pm     Reply with quote

tnx guy for the effort...but it's in javascript...i still dont know anything about java...gonna try it as well...tnx for the help though
Pattons3rd



Joined: 28 Dec 2006
Posts: 1212
Location: Colorado

PostPosted: Tue Jul 10, 2007 4:39 am     Reply with quote

Javascript is not really related to java and is quite simple.
Did you try just pasting the code into a HTML document?
It should work fine.
angelprone



Joined: 05 Jul 2007
Posts: 15

PostPosted: Wed Jul 11, 2007 5:36 pm     Reply with quote

ei Pattons3rd tnx for the code...it really works...tnx a lot...

but still i need another favor...if possible...what about the code for displaying the current date....

tnx...

Smile
Pattons3rd



Joined: 28 Dec 2006
Posts: 1212
Location: Colorado

PostPosted: Thu Jul 12, 2007 4:26 am     Reply with quote

Just add something like
Code:

theTime += now.getMonth() + 1) +"/"+now.getDate()+ "/"+now.getYear()+ " ";
angelprone



Joined: 05 Jul 2007
Posts: 15

PostPosted: Thu Jul 12, 2007 4:22 pm     Reply with quote

Pattons3rd again tnx for replying but i always got an error on the page saying "clockspan is null or is not an object..." i need your help on this...the time and date does not appear now on the screen....
angelprone



Joined: 05 Jul 2007
Posts: 15

PostPosted: Thu Jul 12, 2007 4:22 pm     Reply with quote

Pattons3rd again tnx for replying but i always got an error on the page saying "clockspan is null or is not an object..." i need your help on this...the time and date does not appear now on the screen....i badly need your help....tnx...
Pattons3rd



Joined: 28 Dec 2006
Posts: 1212
Location: Colorado

PostPosted: Fri Jul 13, 2007 3:41 am     Reply with quote

Did you use the whole script?
Even the <div>?
angelprone



Joined: 05 Jul 2007
Posts: 15

PostPosted: Fri Jul 13, 2007 4:59 pm     Reply with quote

i put this code in the <head> part after the <meta>

<script type="text/javascript" language="javascript1.5">
<!-- Hide script from old browsers

window.onload = theClock

function theClock() {
now = new Date;

theTime += now.getMonth() + 1) +"/"+now.getDate()+ "/"+now.getYear()+ "&nbsp;";
theTime = ((now.getHours() > 0 && now.getHours() < 13)) ? now.getHours() : (now.getHours() == 0) ? 12 : now.getHours()-12;
theTime += (now.getMinutes() > 9) ? ":" + now.getMinutes() : ":0" + now.getMinutes();
theTime += (now.getSeconds() > 9) ? ":" + now.getSeconds() : ":0" + now.getSeconds();
theTime += (now.getHours() < 12) ? " am" : " pm";

clockSpan = document.getElementById("myClock");
clockSpan.replaceChild(document.createTextNode(theTime), clockSpan.firstChild);

setTimeout("theClock()",1000);
}

// End hiding script from old browsers -->
</script>

then this one at the <body> part

The current time is <span id="myClock">?</span>

i had also included your code for the date...but still the display for the date and time does not appear...i will try to put <div> tag...tnx
Pattons3rd



Joined: 28 Dec 2006
Posts: 1212
Location: Colorado

PostPosted: Sat Jul 14, 2007 4:08 am     Reply with quote

Try it like this.
Code:
<script type="text/javascript" language="javascript">
<!-- Hide script from old browsers
window.onload = theClock

function theClock() {
now = new Date;

theTime += now.getMonth() + 1) +"/"+now.getDate()+ "/"+now.getYear()+ "&nbsp;";
theTime += ((now.getHours() > 0 && now.getHours() < 13)) ? now.getHours() : (now.getHours() == 0) ? 12 : now.getHours()-12;
theTime += (now.getMinutes() > 9) ? ":" + now.getMinutes() : ":0" + now.getMinutes();
theTime += (now.getSeconds() > 9) ? ":" + now.getSeconds() : ":0" + now.getSeconds();
theTime += (now.getHours() < 12) ? " am" : " pm";

clockSpan = document.getElementById("myClock");
clockSpan.replaceChild(document.createTextNode(theTime), clockSpan.firstChild);

setTimeout("theClock()",1000);
}

// End hiding script from old browsers -->
</script>


and see what happens if you have the <span>.

Also, what browser are you using?
angelprone



Joined: 05 Jul 2007
Posts: 15

PostPosted: Tue Jul 17, 2007 8:44 pm     Reply with quote

Pattons3rd tnx for the reply...gonna try it now...

im using firefox 2 and ie 7

tnx...
Pattons3rd



Joined: 28 Dec 2006
Posts: 1212
Location: Colorado

PostPosted: Wed Jul 18, 2007 4:29 am     Reply with quote

Okay, let me know how it turns out...
angelprone



Joined: 05 Jul 2007
Posts: 15

PostPosted: Wed Jul 18, 2007 5:25 pm     Reply with quote

it still displays nothing...help me...i tried it both in firefox and ie7 Crying or Very sad
indyjoe



Joined: 16 Jan 2008
Posts: 1

PostPosted: Wed Jan 16, 2008 7:06 pm     Reply with quote

angelprone wrote:
it still displays nothing...help me...i tried it both in firefox and ie7 Crying or Very sad


Hey there,
I know this will probably strain you to the limit, but I am asking you to try this code and see what happens! Here it is:

(be sure to copy the below and paste it into your html page.)

<SCRIPT LANGUAGE="JavaScript">
<!--

function getCorrectedYear(year) {
year = year - 0;
if (year < 70) return (2000 + year);
if (year < 1900) return (1900 + year);
return year;
}

var lmod = new Date();
var monthname;
var lmonth = lmod.getMonth();
if (lmonth == 0) monthname = "January";
if (lmonth == 1) monthname = "February";
if (lmonth == 2) monthname = "March";
if (lmonth == 3) monthname = "April";
if (lmonth == 4) monthname = "May";
if (lmonth == 5) monthname = "June";
if (lmonth == 6) monthname = "July";
if (lmonth == 7) monthname = "August";
if (lmonth == Cool monthname = "September";
if (lmonth == 9) monthname = "October";
if (lmonth == 10) monthname = "November";
if (lmonth == 11) monthname = "December";

var yearstr = getCorrectedYear(lmod.getYear());

var outstr = monthname + " " + lmod.getDate() + ", " + yearstr;
document.write(outstr);
// -->

-------------------------------------------------------------------------------------------

</SCRIPT>Step One
Paste the following JavaScript code into the <HEAD> of your Web page:

<SCRIPT language="javascript">

<!-- hide javascript

function StartClock12() {
Time12 = new Date();
Cur12Hour = Time12.getHours();
Cur12Mins = Time12.getMinutes();
Cur12Secs = Time12.getSeconds();
The12Time = (Cur12Hour > 12) ? Cur12Hour - 12 : Cur12Hour;
The12Time += ((Cur12Mins < 10) ? ':0' : ':') + Cur12Mins;
The12Time += ((Cur12Secs < 10) ? ':0' : ':') + Cur12Secs;
The12Time += (Cur12Hour > 12) ? ' PM': ' AM';
document.CForm.Clock12.value = The12Time;
window.status = The12Time;
setTimeout('StartClock12()',1000);
}

function StartDate() {
TDay = new Array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
TMonth = new Array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
TDate = new Date();
CurYear = TDate.getYear();
CurMonth = TDate.getMonth();
CurDayOw = TDate.getDay();
CurDay= TDate.getDate();
TheDate = TDay[CurDayOw] + ', ';
TheDate += TMonth[CurMonth] + ' ';
TheDate += CurDay + ', ';
TheDate += ((CurYear%1900)+1900);
document.CForm.CDate.value = TheDate;
}

// done hiding -->

</SCRIPT>

================================================

Step Two
Add the onLoad event handler to the page's <BODY> tag:

<BODY onLoad="StartClock12();StartDate()";>

Step Three
Then paste the code below into the <BODY> section (add layout and decoration as you see fit):

<FORM name="CForm">
<INPUT type="text" name="Clock12" size="12">
<INPUT type="text" name="CDate" size="29">
</FORM>

That's it. You've built a virtual Big Ben.
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum Index -> HTML Tools All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
 
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial