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

Need help to remove list of days from date script

P: n/a
Need help to remove list of days from date script. Need format "June
07, 2006"
<SCRIPT LANGUAGE="JavaScript">

<!-- Begin

// Get today's current date.
var now = new Date();

// Array list of days.
var days = new
Array('Sunday','Monday','Tuesday','Wednesday','Thu rsday','Friday','Saturday');

// Array list of months.
var months = new
Array('January','February','March','April','May',' June','July','August','September','October','Novem ber','December');

// Calculate the number of the current day in the week.
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

// Calculate four digit year.
function fourdigits(number) {
return (number < 1000) ? number + 1900 : number;
}

// Join it all together
today = days[now.getDay()] + ", " +
months[now.getMonth()] + " " +
date + ", " +
(fourdigits(now.getYear())) ;

// Print out the data.
document.write(today);

// End -->
</script>
thanks.
Mistral

Jun 7 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
mistral wrote:
Need help to remove list of days from date script. Need format "June
07, 2006"
Some ideas below...

<SCRIPT LANGUAGE="JavaScript">
The language attribute is deprecated, type is required:

<script type="text/javascript">

<!-- Begin
Do not use HTML comments inside script elements, it is completely
unnecessary and may be harmful in some circumstances.

// Get today's current date.
var now = new Date();
That creates a date object that can be used to get the date at the time
the object was created.

// Array list of days.
var days = new
Array('Sunday','Monday','Tuesday','Wednesday','Thu rsday','Friday','Saturday');
Apparently you don't want this array, so just deleted it.

// Array list of months.
var months = new
Array('January','February','March','April','May',' June','July','August','September','October','Novem ber','December');
It can be simpler to initialise the months array with an "initialiser":

var months = ['January', 'February', 'March', 'April',
'May', 'June', 'July', 'August',
'September', 'October', 'November', 'December'];

// Calculate the number of the current day in the week.
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
That gets the date, not the day number. To get a 2 digit date as a
string, you could use:

var now = new Date();
var nowDate = now.getDate();
nowDate = (nowDate<10)? '0'+nowDate : ''+nowDate;
I think it's not a good idea to have a variable called 'date' when there
is a Date object (not critical, just a preference).

// Calculate four digit year.
function fourdigits(number) {
return (number < 1000) ? number + 1900 : number;
Or just:

var year = now.getFullYear();

getFullYear() is not supported by some old browsers (IE 4 at least I
think), you may need to add some feature detection or fall-back.

// Join it all together
today = days[now.getDay()] + ", " +
months[now.getMonth()] + " " +
date + ", " +
(fourdigits(now.getYear())) ;


If you aren't going to re-use the date string, write it directly:

document.write(
months[now.getMonth()] + ' ' + nowDate + ', ' + year
);
[...]
--
Rob
Jun 7 '06 #2

P: n/a

RobG писал(а):
mistral wrote:
Need help to remove list of days from date script. Need format "June
07, 2006" Some ideas below...

<SCRIPT LANGUAGE="JavaScript">

The language attribute is deprecated, type is required:

<script type="text/javascript">
<!-- Begin

Do not use HTML comments inside script elements, it is completely
unnecessary and may be harmful in some circumstances.
// Get today's current date.
var now = new Date();

That creates a date object that can be used to get the date at the
time
the object was created.
// Array list of days.
var days = new

Array('Sunday','Monday','Tuesday','Wednesday','Thu rsday','Friday','Saturday');

Apparently you don't want this array, so just deleted it.
// Array list of months.
var months = new

Array('January','February','March','April','May',' June','July','August','September','October','Novem ber','December');

It can be simpler to initialise the months array with an
"initialiser":

var months = ['January', 'February', 'March', 'April',
'May', 'June', 'July', 'August',
'September', 'October', 'November', 'December'];
// Calculate the number of the current day in the week.
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();

That gets the date, not the day number. To get a 2 digit date as a
string, you could use:

var now = new Date();
var nowDate = now.getDate();
nowDate = (nowDate<10)? '0'+nowDate : ''+nowDate;
I think it's not a good idea to have a variable called 'date' when
there
is a Date object (not critical, just a preference).
// Calculate four digit year.
function fourdigits(number) {
return (number < 1000) ? number + 1900 : number;

Or just:

var year = now.getFullYear();

getFullYear() is not supported by some old browsers (IE 4 at least I
think), you may need to add some feature detection or fall-back.
// Join it all together
today = days[now.getDay()] + ", " +
months[now.getMonth()] + " " +
date + ", " +
(fourdigits(now.getYear())) ;

If you aren't going to re-use the date string, write it directly:

document.write(
months[now.getMonth()] + ' ' + nowDate + ', ' + year
);

[...]

Rob
--------------------------------------------
Hi,

I tried implement this ideas as follows, but script not work at all:

<script type="text/javascript">

var now = new Date();

var months = ['January', 'February', 'March', 'April',
'May', 'June', 'July', 'August', 'September', 'October',
'November', 'December'];

var now = new Date();

var nowDate = now.getDate();

nowDate = (nowDate<10)? '0'+nowDate : ''+nowDate;

function fourdigits(number) {
return (number < 1000) ? number + 1900 : number;

document.write(
months[now.getMonth()] + ' ' + nowDate + ', ' + year
);

</script>

Jun 7 '06 #3

P: n/a
JRS: In article <11**********************@h76g2000cwa.googlegroups .com>
, dated Wed, 7 Jun 2006 09:22:38 remote, seen in
news:comp.lang.javascript, mistral <po*******@softhome.net> posted :

Please find out how to quote.
// Calculate four digit year.
function fourdigits(number) {
return (number < 1000) ? number + 1900 : number;
Missing }
Or just:

var year = now.getFullYear();

getFullYear() is not supported by some old browsers (IE 4 at least I
think), you may need to add some feature detection or fall-back.
It is supported in IE4 as supplied with Win98 first UK release.
I tried implement this ideas as follows, but script not work at all:

<script type="text/javascript">

var now = new Date();
Superfluous.

var months = ['January', 'February', 'March', 'April',
'May', 'June', 'July', 'August', 'September', 'October',
'November', 'December'];

var now = new Date();

var nowDate = now.getDate();

nowDate = (nowDate<10)? '0'+nowDate : ''+nowDate;

function fourdigits(number) {
return (number < 1000) ? number + 1900 : number;
Needs trailing }
That fourdigits will fail in browsers in which getYear() returns
year%100; it's been said that such browsers exist(ed).

function fourdigits(number) { return 2000 + number%100 }
// should, for current date, suffice for all but the youngest
programmer.
Needs
year = fourdigits(now.getYear())
or
year = now.getFullYear()
or
year = getFY(now)

document.write(
months[now.getMonth()] + ' ' + nowDate + ', ' + year
);

</script>


Read the newsgroup FAQ; see below.

--
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.
Jun 7 '06 #4

P: n/a
I there some expert which can show how should look full correct
javascript for current date, that works normally(IE, Firefox, Netscape)
? Not comments, but full correct javascript.

mistral

Jun 8 '06 #5

P: n/a
JRS: In article <11**********************@j55g2000cwa.googlegroups .com>
, dated Thu, 8 Jun 2006 05:04:52 remote, seen in
news:comp.lang.javascript, mistral <po*******@softhome.net> posted :
I there some expert which can show how should look full correct
javascript for current date, that works normally(IE, Firefox, Netscape)
? Not comments, but full correct javascript.

Yes.

But, as you have ignored previous advice, experts may now ignore you.

Note, however, that Merkins often use a format, known as FFF, which
conflicts both with common sense and with the applicable international
standard.

--
John Stockton, Surrey, UK. yyww merlyn demon co uk Turnpike v4.00 MIME
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jun 8 '06 #6

P: n/a
Dr John Stockton said the following on 6/8/2006 4:52 PM:
JRS: In article <11**********************@j55g2000cwa.googlegroups .com>
, dated Thu, 8 Jun 2006 05:04:52 remote, seen in
news:comp.lang.javascript, mistral <po*******@softhome.net> posted :
I there some expert which can show how should look full correct
javascript for current date, that works normally(IE, Firefox, Netscape)
? Not comments, but full correct javascript. Yes.
But, as you have ignored previous advice, experts may now ignore you.


If you ignored half the posts you reply to with your pedantic garbage,
you wouldn't be half as bad.
Note, however, that Merkins often use a format, known as FFF, which
conflicts both with common sense and with the applicable international
standard.


Your pedantic stupidity never ceases to amaze me.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 8 '06 #7

P: n/a
> Dr John Stockton said the following on 6/8/2006 4:52 PM:

I there some expert which can show how should look full correct
javascript for current date, that works normally(IE, Firefox, Netscape)
? Not comments, but full correct javascript.
Yes.

But, as you have ignored previous advice, experts may now ignore you. If you ignored half the posts you reply to with your pedantic garbage,
you wouldn't be half as bad. Note, however, that Merkins often use a format, known as FFF, which
conflicts both with common sense and with the applicable international
standard. Your pedantic stupidity never ceases to amaze me. Randy

============================
"But, as you have ignored previous advice, experts may now ignore you."

I not ingnored previous advice, I DONT UNDERSTAND IT. If you javascript
exprert, can you you show *full and correct code snippet*? Not
comments, not abstract Usenet discussion -I dont understand it (and
your english), but human readable code snippet, ready for use in html
page?

Jun 9 '06 #8

P: n/a
JRS: In article <11**********************@f6g2000cwb.googlegroups. com>,
dated Fri, 9 Jun 2006 03:04:23 remote, seen in
news:comp.lang.javascript, mistral <po*******@softhome.net> posted :
"But, as you have ignored previous advice, experts may now ignore you."

I not ingnored previous advice, I DONT UNDERSTAND IT.

Which parts of "Please find out how to quote." and "Read the newsgroup
FAQ; see below." did you fail to understand?

--
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.
Jun 9 '06 #9

P: n/a

Dr John Stockton писал(а):

JRS: In article
<11**********************@f6g2000cwb.googlegroups. com>,
dated Fri, 9 Jun 2006 03:04:23 remote, seen in
news:comp.lang.javascript, mistral <po*******@softhome.net> posted :
"But, as you have ignored previous advice, experts may now ignore you."
I not ingnored previous advice, I DONT UNDERSTAND IT. Which parts of "Please find out how to quote." and "Read the newsgroup
FAQ; see below." did you fail to understand?
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00IE 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.

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

I dont understand your expert advice - at all. Sorry.

Mistral

Jun 12 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.