| View previous topic :: View next topic |
| Author |
Message |
angelprone
Joined: 05 Jul 2007 Posts: 15
|
Posted: Thu Jul 05, 2007 6:14 pm displaying the current time and date at the top of the page |
|
|
|
| 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
|
|
angelprone
Joined: 05 Jul 2007 Posts: 15
|
Posted: Mon Jul 09, 2007 10:21 pm |
|
|
|
| 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
|
Posted: Tue Jul 10, 2007 4:39 am |
|
|
|
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
|
Posted: Wed Jul 11, 2007 5:36 pm |
|
|
|
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...
 |
|
Pattons3rd

Joined: 28 Dec 2006 Posts: 1212 Location: Colorado
|
Posted: Thu Jul 12, 2007 4:26 am |
|
|
|
Just add something like
| Code: |
theTime += now.getMonth() + 1) +"/"+now.getDate()+ "/"+now.getYear()+ " "; |
|
|
angelprone
Joined: 05 Jul 2007 Posts: 15
|
Posted: Thu Jul 12, 2007 4:22 pm |
|
|
|
| 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
|
Posted: Thu Jul 12, 2007 4:22 pm |
|
|
|
| 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
|
Posted: Fri Jul 13, 2007 3:41 am |
|
|
|
Did you use the whole script?
Even the <div>? |
|
angelprone
Joined: 05 Jul 2007 Posts: 15
|
Posted: Fri Jul 13, 2007 4:59 pm |
|
|
|
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()+ " ";
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
|
Posted: Sat Jul 14, 2007 4:08 am |
|
|
|
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()+ " ";
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
|
Posted: Tue Jul 17, 2007 8:44 pm |
|
|
|
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
|
Posted: Wed Jul 18, 2007 4:29 am |
|
|
|
| Okay, let me know how it turns out... |
|
angelprone
Joined: 05 Jul 2007 Posts: 15
|
Posted: Wed Jul 18, 2007 5:25 pm |
|
|
|
it still displays nothing...help me...i tried it both in firefox and ie7  |
|
indyjoe
Joined: 16 Jan 2008 Posts: 1
|
Posted: Wed Jan 16, 2008 7:06 pm |
|
|
|
| angelprone wrote: |
it still displays nothing...help me...i tried it both in firefox and ie7  |
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 == 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. |
|
|