By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,695 Members | 1,638 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,695 IT Pros & Developers. It's quick & easy.

Javascript DATE&TIME HTML

P: n/a
ME
can someone tell me how to make this first one work??, located here:
http://javascript.about.com/library/...#examplesource

This second one, well, dreamweaver eats the code, removes the code as bad.
Any help here? Please? 2nd located here:
http://www.dynamicdrive.com/dynamicindex6/clock3.htm
Appreciated,
M.E.
Jul 23 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
"ME" <me@mine.com> wrote in message news:V9********************@eatel.net...
can someone tell me how to make this first one work??, located here:
http://javascript.about.com/library/...#examplesource

What doesn't work?

<html>
<head>
<title>ShowDateTime.htm</title>
<script type="text/javascript">
var showDateShort = 1;
var showDate= 2;
var showDateTime= 3;
var showTime= 4;

function ShowDateTime(dateStyle) {
var today = new Date();
var dStr = "";
switch (dateStyle) {
case showDateShort:
dStr = today.toDateString();
break;
case showDateTime:
dStr = today.toLocaleString();
break;
case showTime:
dStr = today.toLocaleTimeString();
break;
case showDate:
default:
dStr = today.toLocaleDateString();
break;
}
document.write(dStr);
}
</script>
</head>
<body>
<script type="text/javascript">
ShowDateTime(showDateShort);
document.write("<br>");
ShowDateTime(showDate);
document.write("<br>");
ShowDateTime(showDateTime);
document.write("<br>");
ShowDateTime(showTime);
</script>
</body>
</html>

This second one, well, dreamweaver eats the code, removes the code as bad.
Any help here? Please? 2nd located here:
http://www.dynamicdrive.com/dynamicindex6/clock3.htm
Again, what doesn't work?

<html>
<head>
<title>DynaDateTime.htm</title>
<script type="text/javascript">
/*
Live Date Script-
Dynamic Drive (www.dynamicdrive.com)
For full source code, installation instructions, 100's more DHTML scripts,
and Terms Of Use,
visit http://www.dynamicdrive.com
*/

var dayarray=new
Array("Sunday","Monday","Tuesday","Wednesday","Thu rsday","Friday","Saturday"
);
var montharray=new
Array("January","February","March","April","May"," June","July","August","Sep
tember","October","November","December");

function getthedate() {
var mydate = new Date();
var year = mydate.getYear();
if (year < 1000) year+=1900;
var day = mydate.getDay();
var month = mydate.getMonth();
var daym = mydate.getDate();
if (daym<10) daym = "0"+daym;
var hours = mydate.getHours();
var minutes = mydate.getMinutes();
var seconds = mydate.getSeconds();
var dn = "AM";
if (hours>=12) dn = "PM";
if (hours>12) hours = hours-12;
if (hours==0) hours = 12;
if (minutes<=9) minutes = "0"+minutes;
if (seconds<=9) seconds = "0"+seconds;
// change font size here
var cdate="<small><font color='000000'
face='Arial'><b>"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+"
"+hours+":"+minutes+":"+seconds+" "+dn+"</b></font></small>"
if (document.all)
document.all.clock.innerHTML = cdate;
else if (document.getElementById)
document.getElementById("clock").innerHTML = cdate;
else
document.write(cdate);
}

if (!document.all && !document.getElementById) getthedate();

function goforit() {
if (document.all || document.getElementById)
setInterval("getthedate()",1000);
}
</script>
</head>
<body onLoad="goforit()">
<span id="clock"></span>
</body>
</html>
Appreciated,
M.E.


Did you watch for word-wrap?
Jul 23 '05 #2

P: n/a
ME
The first one I do not know how to paste into the html page. The second,
dreamweaver removes the <span tags everytime I open the html. Word Wrap?
Like how?

ME


"McKirahan" <Ne**@McKirahan.com> wrote in message
news:bzb_c.368789$%_6.269826@attbi_s01...
"ME" <me@mine.com> wrote in message news:V9********************@eatel.net...
can someone tell me how to make this first one work??, located here:

http://javascript.about.com/library/...#examplesource
What doesn't work?

<html>
<head>
<title>ShowDateTime.htm</title>
<script type="text/javascript">
var showDateShort = 1;
var showDate= 2;
var showDateTime= 3;
var showTime= 4;

function ShowDateTime(dateStyle) {
var today = new Date();
var dStr = "";
switch (dateStyle) {
case showDateShort:
dStr = today.toDateString();
break;
case showDateTime:
dStr = today.toLocaleString();
break;
case showTime:
dStr = today.toLocaleTimeString();
break;
case showDate:
default:
dStr = today.toLocaleDateString();
break;
}
document.write(dStr);
}
</script>
</head>
<body>
<script type="text/javascript">
ShowDateTime(showDateShort);
document.write("<br>");
ShowDateTime(showDate);
document.write("<br>");
ShowDateTime(showDateTime);
document.write("<br>");
ShowDateTime(showTime);
</script>
</body>
</html>

This second one, well, dreamweaver eats the code, removes the code as bad. Any help here? Please? 2nd located here:
http://www.dynamicdrive.com/dynamicindex6/clock3.htm
Again, what doesn't work?

<html>
<head>
<title>DynaDateTime.htm</title>
<script type="text/javascript">
/*
Live Date Script-
Dynamic Drive (www.dynamicdrive.com)
For full source code, installation instructions, 100's more DHTML scripts,
and Terms Of Use,
visit http://www.dynamicdrive.com
*/

var dayarray=new

Array("Sunday","Monday","Tuesday","Wednesday","Thu rsday","Friday","Saturday" );
var montharray=new
Array("January","February","March","April","May"," June","July","August","Sep tember","October","November","December");

function getthedate() {
var mydate = new Date();
var year = mydate.getYear();
if (year < 1000) year+=1900;
var day = mydate.getDay();
var month = mydate.getMonth();
var daym = mydate.getDate();
if (daym<10) daym = "0"+daym;
var hours = mydate.getHours();
var minutes = mydate.getMinutes();
var seconds = mydate.getSeconds();
var dn = "AM";
if (hours>=12) dn = "PM";
if (hours>12) hours = hours-12;
if (hours==0) hours = 12;
if (minutes<=9) minutes = "0"+minutes;
if (seconds<=9) seconds = "0"+seconds;
// change font size here
var cdate="<small><font color='000000'
face='Arial'><b>"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+" "+hours+":"+minutes+":"+seconds+" "+dn+"</b></font></small>"
if (document.all)
document.all.clock.innerHTML = cdate;
else if (document.getElementById)
document.getElementById("clock").innerHTML = cdate;
else
document.write(cdate);
}

if (!document.all && !document.getElementById) getthedate();

function goforit() {
if (document.all || document.getElementById)
setInterval("getthedate()",1000);
}
</script>
</head>
<body onLoad="goforit()">
<span id="clock"></span>
</body>
</html>
Appreciated,
M.E.


Did you watch for word-wrap?

Jul 23 '05 #3

P: n/a
On Sat, 4 Sep 2004 13:49:18 -0500, ME wrote:
dreamweaver removes the <span tags everytime I open the html.


Patient: "It hurts when I bang
my head against the wall."

Doctor: "Don't bang your head against
the wall. That will be $130, pay the
receptionist on the way out."

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #4

P: n/a
JRS: In article <bzb_c.368789$%_6.269826@attbi_s01>, dated Sat, 4 Sep
2004 04:32:08, seen in news:comp.lang.javascript, McKirahan
<Ne**@McKirahan.com> posted :
dStr = today.toLocaleTimeString();
dStr = today.toLocaleDateString();
Functions not available in all browsers. The presumed effect should be
more widely available by a RegExp edit of today.toLocaleString() ;
however, the format given is what the browser writers thought right for
the locale, and may be misleading.

if (year < 1000) year+=1900;
AIUI, does not work correctly on all systems. I hear that one or more
systems return Year%100 for getYear.

Use getFullYear if assumable as available; otherwise, a substitute using
getYear and getTime is available and was presented here fairly recently
- see also my js-date0.htm#gFY
if (daym<10) daym = "0"+daym;
if (minutes<=9) minutes = "0"+minutes;
if (seconds<=9) seconds = "0"+seconds;
Better to use a function for this repeated code.

function goforit() {
if (document.all || document.getElementById)
setInterval("getthedate()",1000);
}


Will not show every second; easily fixed. Author needs to do some
reading.

By the way, the 12-hour clock should not be used on the Web; it is a
mere American affectation. It should be used only for real-time
analogue displays.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of 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 23 '05 #5

P: n/a
On 2004/09/04 16:57, in article xn**************@merlyn.demon.co.uk, "Dr
John Stockton" <sp**@merlyn.demon.co.uk> wrote:
By the way, the 12-hour clock should not be used on the Web; it is a
mere American affectation. It should be used only for real-time
analogue displays.


Speaking as a mere Brit, this is a bit much John. The 12-hour and 24-hour
clocks are more or less universally recognised everywhere you go in the
world. Moreover, it is the 24-hour clock that is the affectation as a simple
consideration of the expression of time in the English (and all other modern
Indo-European) languages will confirm. Which perhaps explains why the
12-hour clock is the one most people habitually prefer.

The 24-hour clock in fact originated as a military device to avoid awkward
and embarrassing moments like launching your part of the offensive 12 hours
after (or before) the guy further up the line.

You'll be telling us that "fall" is an Americanism for "autumn" next. What
would Shakespeare think?

"Neither my husband, nor the slave return'd
That in such haste I sent to seek his master!
Sure, Luciana, it is 14:00 hours."

- Comedy of Errors, Act II, Scene I (American web version)

Dr Ian Sedwell

Jul 23 '05 #6

P: n/a
JRS: In article <BD***********************@btclick.com>, dated Mon, 6
Sep 2004 22:52:32, seen in news:comp.lang.javascript, Ian Sedwell
<ia*********@btclick.com> posted :
On 2004/09/04 16:57, in article xn**************@merlyn.demon.co.uk, "Dr
John Stockton" <sp**@merlyn.demon.co.uk> wrote:
By the way, the 12-hour clock should not be used on the Web; it is a
mere American affectation. It should be used only for real-time
analogue displays.

Speaking as a mere Brit, this is a bit much John. The 12-hour and 24-hour
clocks are more or less universally recognised everywhere you go in the
world. Moreover, it is the 24-hour clock that is the affectation as a simple
consideration of the expression of time in the English (and all other modern
Indo-European) languages will confirm. Which perhaps explains why the
12-hour clock is the one most people habitually prefer.


The 24-hour clock is simpler, and is understood everywhere; it is
therefore better than the 12-hour one.

The 12-hour clock is in fact also fairly well understood, though that
will diminish as the proportion of digital to analogue timepieces
increases (Yes, I know that there are 12-h digital ones; but, sundials
apart, there are few 24-h analogue ones). But there is a greater risk
of error on its use.

24-hour times, with fixed-width fields, can be sorted as strings;
12-hour ones need careful modification (js-date0.htm#TCp> or full
conversion first.

Getting the 24-hour clock to be considered the norm is a step on the way
towards stamping out the traditional European D M Y and the ludicrous M
D Y for dates and getting, for everyone, the full benefit of ISO 8601.

You'll be telling us that "fall" is an Americanism for "autumn" next. What
would Shakespeare think?


It is an Americanism. The language of England has developed since
Shakespeare's time. That of America has diverged.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
PAS EXE etc : <URL:http://www.merlyn.demon.co.uk/programs/> - see 00index.htm
Dates - miscdate.htm moredate.htm js-dates.htm pas-time.htm critdate.htm etc.
Jul 23 '05 #7

P: n/a
On 2004/09/07 11:11, in article mR**************@merlyn.demon.co.uk, "Dr
John Stockton" <sp**@merlyn.demon.co.uk> wrote:
JRS: In article <BD***********************@btclick.com>, dated Mon, 6
Sep 2004 22:52:32, seen in news:comp.lang.javascript, Ian Sedwell
<ia*********@btclick.com> posted :
On 2004/09/04 16:57, in article xn**************@merlyn.demon.co.uk, "Dr
John Stockton" <sp**@merlyn.demon.co.uk> wrote:
By the way, the 12-hour clock should not be used on the Web; it is a
mere American affectation. It should be used only for real-time
analogue displays.

Speaking as a mere Brit, this is a bit much John. The 12-hour and 24-hour
clocks are more or less universally recognised everywhere you go in the
world. Moreover, it is the 24-hour clock that is the affectation as a simple
consideration of the expression of time in the English (and all other modern
Indo-European) languages will confirm. Which perhaps explains why the
12-hour clock is the one most people habitually prefer.


The 24-hour clock is simpler, and is understood everywhere; it is
therefore better than the 12-hour one.


Agreed, but that gives nobody the right to prescribe the one and proscribe
the other. People habitually use the 12-hour clock. Listen to program times
as they are announced on the TV, look at how English and other languages
assiduously incorporate the 12-hour clock as their normal mode of temporal
expression.
The 12-hour clock is in fact also fairly well understood, though that
will diminish as the proportion of digital to analogue timepieces
increases (Yes, I know that there are 12-h digital ones; but, sundials
apart, there are few 24-h analogue ones). But there is a greater risk
of error on its use.

24-hour times, with fixed-width fields, can be sorted as strings;
12-hour ones need careful modification (js-date0.htm#TCp> or full
conversion first.
Agreed. So what's wrong with making things easy for the poor user and doing
things the way they want for a change. It is a simple matter to convert a
12-hour date string to a 24-hour one, perform whatever manipulations are
required and change the result back to 12-hours. The user's happy, the
programmer's happy and the machine gets to chew a few more CPU cycles. What
the hell. People are important, not computers.

Getting the 24-hour clock to be considered the norm is a step on the way
towards stamping out the traditional European D M Y and the ludicrous M
D Y for dates and getting, for everyone, the full benefit of ISO 8601.
Completely agree.
You'll be telling us that "fall" is an Americanism for "autumn" next. What
would Shakespeare think?


It is an Americanism. The language of England has developed since
Shakespeare's time. That of America has diverged.


Sorry. It's not. It's actually from the Old Saxon "fallain", meaning to fall
and was used to describe the change of season at the end of summer. It
retained this usage through the related Old English word "feallan" and the
Old Norse "falla". Its use persisted in Middle and early Modern English and
was taken to America by the early settlers. It is a classic example of how
many "Americanisms" are in fact remnants of an older form of Modern English
which we Brits have either dropped completely or now regard as archaic.

All language develop and diverge. Even computer languages, though these are
trivial by comparison. A quick glance through de Saussure will convince you
that language is a continually changing thing. No one language is more
primitive, or more sophisticated than any other; nor are any dialects within
languages.

Jul 23 '05 #8

P: n/a
JRS: In article <BD***********************@btclick.com>, dated Tue, 7
Sep 2004 22:09:53, seen in news:comp.lang.javascript, Ian Sedwell
<ia*********@btclick.com> posted :
On 2004/09/07 11:11, in article mR**************@merlyn.demon.co.uk, "Dr
John Stockton" <sp**@merlyn.demon.co.uk> wrote: Agreed. So what's wrong with making things easy for the poor user and doing
things the way they want for a change. It is a simple matter to convert a
12-hour date string to a 24-hour one, perform whatever manipulations are
required and change the result back to 12-hours. The user's happy, the
programmer's happy and the machine gets to chew a few more CPU cycles. What
the hell. People are important, not computers.


It's not simple enough for some of those who post here.

You'll be telling us that "fall" is an Americanism for "autumn" next. What
would Shakespeare think?


It is an Americanism. The language of England has developed since
Shakespeare's time. That of America has diverged.


Sorry. It's not. It's actually from the Old Saxon "fallain", meaning to fall
and was used to describe the change of season at the end of summer. It
retained this usage through the related Old English word "feallan" and the
Old Norse "falla". Its use persisted in Middle and early Modern English and
was taken to America by the early settlers. It is a classic example of how
many "Americanisms" are in fact remnants of an older form of Modern English
which we Brits have either dropped completely or now regard as archaic.

All language develop and diverge. Even computer languages, though these are
trivial by comparison. A quick glance through de Saussure will convince you
that language is a continually changing thing. No one language is more
primitive, or more sophisticated than any other; nor are any dialects within
languages.


That's right. It's an Americanism, because they have retained it and we
have not. It's just not an original Americanism.

--
John Stockton, Surrey, UK. ??*@merlyn.demon.co.uk Turnpike v4.00 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.

Food expiry ambiguities: <URL:http://www.merlyn.demon.co.uk/date2k-3.htm#Food>
Jul 23 '05 #9

P: n/a
> That's right. It's an Americanism, because they have retained it and we
have not. It's just not an original Americanism.

Oh man! You're priceless! LOL
Jul 23 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.