Need help to remove list of days from date script

M

mistral

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','Thursday','Friday','Saturday');

// Array list of months.
var months = new
Array('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();

// 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
 
R

RobG

mistral said:
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:

<!-- 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','Thursday','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','November','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
);


[...]
 
M

mistral

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','Thursday','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','November','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>
 
D

Dr John Stockton

JRS: In article <[email protected]>
, dated Wed, 7 Jun 2006 09:22:38 remote, seen in
mistral <[email protected]> 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.
 
M

mistral

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
 
D

Dr John Stockton

JRS: In article <[email protected]>
, dated Thu, 8 Jun 2006 05:04:52 remote, seen in
news:comp.lang.javascript said:
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.
 
R

Randy Webb

Dr John Stockton said the following on 6/8/2006 4:52 PM:
JRS: In article <[email protected]>
, dated Thu, 8 Jun 2006 05:04:52 remote, seen in

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.
 
M

mistral

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.
============================
"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?
 
D

Dr John Stockton

JRS: In article <[email protected]>,
dated Fri, 9 Jun 2006 03:04:23 remote, seen in
news:comp.lang.javascript said:
"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?
 
M

mistral

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

JRS: In article
dated Fri, 9 Jun 2006 03:04:23 remote, seen in
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. [email protected] Turnpike v4.00IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of <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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top