473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Display current time

JCO
How do you do this. I would like for it to be as dynamic as each page
refresh.
Thanks
Jul 20 '05 #1
7 2019
" JCO" <J.********@verizon.net> wrote in message
news:ZW*****************@nwrddc03.gnilink.net...
How do you do this. I would like for it to be as dynamic as each page
refresh.
Thanks

Will this help? Test as-is; watch for word-wrap.

<html>
<head>
<title>time.htm</title>
</head>
<body>
<script type="text/javascript">
document.write('<span id="clock"></span>');
isNS4 = (document.layers) ? true : false;
isIE4 = (document.all && !document.getElementById) ? true : false;
isIE5 = (document.all && document.getElementById) ? true : false;
isNS6 = (!document.all && document.getElementById) ? true : false;
var clock = "";
if (isNS4) {
clock = document.layers["clock"];
} else if (isIE4) {
clock = document.all["clock"];
} else if (isIE5 || isNS6) {
clock = document.getElementById("clock");
}
function clockTick() {
var Now = new Date();
var Nhh = Now.getHours();
var Nnn = Now.getMinutes();
if (Nnn < 10) Nnn = "0" + Nnn;
var Nss = Now.getSeconds();
if (Nss < 10) Nss = "0" + Nss;
var Nap = "AM";
if (Nhh >= 12) {
Nhh -= 12;
Nap = "PM";
}
if (Nhh == 0) Nhh = 12;
var Str = new Array();
Str[0] = "<font color='#000000'>";
Str[9] = Nhh;
Str[10] = ":";
Str[11] = Nnn;
Str[12] = ":";
Str[13] = Nss;
Str[14] = " ";
Str[15] = Nap;
Str[16] = "</font> &nbsp; ";
var Clock = Str.join("");
clock.innerHTML = Clock;
}
setInterval("clockTick()",1000);
</script>
</body>
</html>
P.S. I'm sure someone will "refine" it!
Jul 20 '05 #2
McKirahan wrote:
" JCO" <J.********@verizon.net> wrote in message
news:ZW*****************@nwrddc03.gnilink.net...
How do you do this. I would like for it to be as dynamic as each page
refresh.
Thanks
Will this help? Test as-is; watch for word-wrap.

<html>
<head>
<title>time.htm</title>
</head>
<body>
<script type="text/javascript">
document.write('<span id="clock"></span>');
isNS4 = (document.layers) ? true : false;
isIE4 = (document.all && !document.getElementById) ? true : false;


IE4 is not the only browser that can pass that test.
isIE5 = (document.all && document.getElementById) ? true : false;
IE5+ is not the only browser that can pass that test.
isNS6 = (!document.all && document.getElementById) ? true : false;
And NS6 is definitely not the only browser that passes that test.
P.S. I'm sure someone will "refine" it!


Doubtful. Discredit it maybe.

Consult the FAQ with regards to dynamically changing page content, it
has its own section. As written, your code will utterly fail in NN4.xx
as it doesn't support innerHTML in any fashion.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #3
"Randy Webb" <hi************@aol.com> wrote in message
news:6b********************@comcast.com...
McKirahan wrote:
P.S. I'm sure someone will "refine" it!


Doubtful. Discredit it maybe.

You would have helped the OP if you had refined the solution offered rather
than just discrediting it.
Jul 20 '05 #4
"McKirahan" <Ne**@McKirahan.com> wrote in message
news:%qqWb.5841$_44.9944@attbi_s52...
P.S. I'm sure someone will "refine" it!
Doubtful. Discredit it maybe.


You would have helped the OP if you had refined the solution
offered rather than just discrediting it.


It wasn't necessarily Randy's intention to help the OP. This isn't,
after all, a help desk, it is a discussion forum. OPs actually getting
help is just a pleasant side effect of that.

The real benefit in the group goes to the regular participants, who you
appear to have decided to join. And to receive that benefit you will
have to be willing to be criticised because if nobody tells you when you
are wrong you will never know how or what you can improve. And then, if
you don't believe that you are not wrong, you can always argue your
case. Though not in this instance as the object inference style of
scripting is completely discredited.

Thinking back to when I started positing in this group, I thought I
understood javascript fairly well. I was very wrong but I needed some
hindsight to appreciate that, and people pointing out where and why I
was wrong. I also needed to react by taking what I was being told on
board and going away and re-doing and re-posting the scripts that had
been criticised until they were right. I learnt a great deal doing that,
more than I had expected was possible.

If you reacted to Randy's comments by identifying what is wrong with
your object inference script and replaced it with a feature detecting
equivalent and posted that you would probably learn something useful
along the way, and the OP would then also benefit. (Though I think your
code is well outside the rather inadequate spec originally posted.)

The relevant part of the FAQ is:-

<URL: http://jibbering.com/faq/#FAQ4_26 >

- which links to quite a good page at apple. The next revision of the
FAQ will also reference a new page, the draft of which is at:-

<URL:
http://www.litotes.demon.co.uk/js_in...er_detect.html
The section on inserting content is:-

<URL: http://jibbering.com/faq/#FAQ4_15 >

- and will also have notes added with the next revision:-

<URL: http://www.litotes.demon.co.uk/js_in..._dynwrite.html


- and may eventually be joined by a page on W3C DOM methods, which you
could investigate in this context as you would only be sacrificing
support for IE 4 if you used those. (Specifically, re-setting the
nodeValue property of the text node within the SPAN element as that is a
lot more efficient than re-writing its innerHTML).

Richard.
Jul 20 '05 #5
McKirahan wrote:
"Randy Webb" <hi************@aol.com> wrote in message
news:6b********************@comcast.com...
McKirahan wrote:
P.S. I'm sure someone will "refine" it!


Doubtful. Discredit it maybe.


You would have helped the OP if you had refined the solution offered rather
than just discrediting it.


The only way to "refine" that script is to discard it and start over.
The reference to the FAQ (and reading it) will do both of you way more
good than me writing a clock script will ever do.

Just for kicks and giggles, you can look at <URL:
http://www.hikksworld.com/clock.html /> though. Its one I made a while
back that has some other things on it, but the clock is there.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #6
JRS: In article <e4kWb.2985$jk2.14236@attbi_s53>, seen in
news:comp.lang.javascript, McKirahan <Ne**@McKirahan.com> posted at Wed,
11 Feb 2004 06:36:58 :-
" JCO" <J.********@verizon.net> wrote in message
news:ZW*****************@nwrddc03.gnilink.net.. .
How do you do this. I would like for it to be as dynamic as each page
refresh.

isNS4 = (document.layers) ? true : false;

You cannot identify browsers in that manner. To some extent, you can
determine the nature of a browser : what it is-or-resembles. To reflect
this, change "isNS4" to "asNS4", etc. But read RC's FAQ notes.

setInterval(..., 1000) does not fire once per second, in at least some
systems. Read the FAQ.

The OP asked for the time to be shown at each page refresh, not
continuously. A mere document.write(new Date()) will do that.

The following can be used for converting proper hours to Merkin ones :
Nap = ["AM","PM"][+(Nhh>11)]
Nhh = 1 + (Nhh+11)%12
Partially tested.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 20 '05 #7
JCO
Thanks everyone for your comments.
I have what I need.

"Dr John Stockton" <sp**@merlyn.demon.co.uk> wrote in message
news:jr**************@merlyn.demon.co.uk...
JRS: In article <e4kWb.2985$jk2.14236@attbi_s53>, seen in
news:comp.lang.javascript, McKirahan <Ne**@McKirahan.com> posted at Wed,
11 Feb 2004 06:36:58 :-
" JCO" <J.********@verizon.net> wrote in message
news:ZW*****************@nwrddc03.gnilink.net.. .
How do you do this. I would like for it to be as dynamic as each page
refresh.

isNS4 = (document.layers) ? true : false;

You cannot identify browsers in that manner. To some extent, you can
determine the nature of a browser : what it is-or-resembles. To reflect
this, change "isNS4" to "asNS4", etc. But read RC's FAQ notes.

setInterval(..., 1000) does not fire once per second, in at least some
systems. Read the FAQ.

The OP asked for the time to be shown at each page refresh, not
continuously. A mere document.write(new Date()) will do that.

The following can be used for converting proper hours to Merkin ones :
Nap = ["AM","PM"][+(Nhh>11)]
Nhh = 1 + (Nhh+11)%12
Partially tested.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE

4 © <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript <URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources. <URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items,

links.
Jul 20 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Agency | last post by:
I'm still working on the bpm counter. I need to have at least 2 displays that are not static. One would be a clock/running time and the other would should the current beat count. How would I...
8
by: Monty | last post by:
Let's say you provide an online service from 7:00AM to 6:00PM Eastern Time (daylight time in the summer). Is there way of showing these hours of availability on a web page in the user's local...
34
by: kroger | last post by:
Hi. I am at a loss to decipher why the javascript on my web page: http://www.psych.nmsu.edu/~jkroger/lab/index.html does not display the date correctly in Firefox. Instead of "2005" for the...
17
by: perryche | last post by:
I have 5records, e.g. Rc1, Rc2, Rc3..., when user open up a form, I want it to open to a particular record (say Rc3) then when user chooses the Record Selector , it will go to Rc2 and , it will go...
2
by: Vaj | last post by:
hi, i would be very thankful if u can help me in solving this problem. my problem is i 've a page in that i'm displaying the creation dates of all files. these dates are like server dates . now...
4
by: Ren | last post by:
Hi all, I am trying to display the current time including milliseconds (two digits only). So for example the current time will have Hour : Minute : Second : Millisecond. Example: ...
3
by: c676228 | last post by:
Hi everyone, I have a piece of code in sales.aspx.vb like this: Protected WithEvents Message As System.Web.UI.WebControls.Label Try ... ChartImage.ImageUrl = "ChartGenerator.aspx?" + DataStr +...
9
by: Frank | last post by:
I have a time saved in a time_t variable. I'd like to be able to display the number of days since then but can't find anything built-in that will help. Failing that I'd like to display the...
4
by: JuAn2226 | last post by:
Hi, can anyone help me . when my program starts there is numbers and time will be display in the form of visual basic. it will run continuesly .My problem here is i dont know how to display the data...
3
by: krzysztof.murkowski | last post by:
Hi, I have problem with JavaScript for gallery of images. From the overview page with thumbnails, after a click on the small picture, the subpage 'slide_show.html' is called, with a number of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.