SearchSearch   

adding to a ddmmyyyy date

 
Goto page Previous  1, 2
   Webmaster Forums (Home) -> Javascript RSS
Next:  Dynamically Generated table does not apply styles  
Author Message
Evertjan.

External


Since: Sep 30, 2005
Posts: 2391



(Msg. 16) Posted: Thu Aug 09, 2007 5:55 pm
Post subject: Re: adding to a ddmmyyyy date
Archived from groups: comp>lang>javascript (more info?)

Dr J R Stockton wrote on 09 aug 2007 in comp.lang.javascript:

> In comp.lang.javascript message <Xns9986EF7F65D6Deejj99 RemoveThis @194.109.133.242>
> , Wed, 8 Aug 2007 21:32:37, Evertjan. <exjxw.hannivoort RemoveThis @interxnl.net>
> posted:
>>
>>> d = new Date(d.getTime() + 50*24*60*60*1000);
>>
>>safer:
>>d.setTime(d.getTime() + 50*24*60*60*1000);
>
> Better, yes; but why safer?

Because this

d = new Date((a[2]), (a[1])-1, (a[0]));
d = new Date(d.getTime() + 50*24*60*60*1000);

is less understandable, so is bound to have more mistakes made.

>>or, also easier:
>>d.setDate(d.getDate() + 50);

Pentakosta [Gr., 50] gives a perfect Pesach to Shavuot+1 arythmatic.

> That's also safer. Starting at Saturday 2007-03-24 23:30, the first
> gives us a Monday and the second a Sunday. 50 days are 7 weeks plus ONE
> day.

Yes, indeed!


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Back to top
Dr J R Stockton

External


Since: May 20, 2007
Posts: 386



(Msg. 17) Posted: Thu Aug 09, 2007 11:31 pm
Post subject: Re: adding to a ddmmyyyy date
Archived from groups: per prev. post (more info?)

In comp.lang.javascript message <f9dk9101ul3 DeleteThis @drn.newsguy.com>, Wed, 8
Aug 2007 16:40:17, Lee <REM0VElbspamtrap DeleteThis @cox.net> posted:
>Thomas 'PointedEars' Lahn said:
>> ...
>Can you explain how your ludicrous multiplication method works
>if the resulting date is earlier than the 10th of the month?

The multiplication method is currently good for generating YYYYMMDD.

It is not good for DDMMYYYY or 8-digit FFF.

OTOH, given that separators are required, consider

d = new Date("1234/01/02") // 1234 Jan 2
X =
String(d.getFullYear()*1e4 + d.getMonth()*1e2 + d.getDate() + 100)
.replace(/(\d{4})(\d\d)(\d\d)/, "$3/$2/$1");

Change the \d{4} to \d+ and the code will be shorter and last longer.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
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.
Back to top
Thomas 'PointedEars' Lahn

External


Since: Sep 05, 2004
Posts: 3405



(Msg. 18) Posted: Fri Aug 10, 2007 9:27 am
Post subject: Re: adding to a ddmmyyyy date
Archived from groups: per prev. post (more info?)

Dr J R Stockton wrote:
> Re another article :

While it may be time-saving for you, it would be polite towards the author
of the article, the potential reader, and prudent in general (e.g. in order
not to demonstrate usually inappropriate practice to the uninitiated by a
regular) if you posted a followup to the article you are referring to, in
which you quoted the relevant parts you are referring to, instead.

> parseInt(S) for S being "08" or "09" gives zero (the standard
> reluctantly allows that); so, in this context, if parseInt
> is used then it does need ', 10'.
>
> But without parseInt, "08" and "09" are taken as eight and nine;
> although "077" is sixty-three, "078" is seventy-eight - at least,
> wherever I've tried it. That seems compatible with ISO/IEC 16262 B.1.

I don't know what ISO/IEC 16262 B.1 says (I won't spend the money required
in order to read it), but if that international standard says the same as
section B.1 of the (freely available) European standard ECMA-262-3 (which
was later approved as ISO/IEC 16262), then the observed behavior would not
be compatible with the compatibility grammar defined there:

| B.1 Additional Syntax
|
| Past editions of ECMAScript have included additional syntax and semantics
| for specifying octal literals and octal escape sequences. These have been
| removed from this edition of ECMAScript. This non-normative annex presents
| uniform syntax and semantics for octal literals and octal escape sequences
| for compatibility with some older ECMAScript programs.
|
| B.1.1 Numeric Literals
|
| The syntax and semantics of section 7.8.3 can be extended as follows:
|
| *Syntax*
|
| NumericLiteral ::
| DecimalLiteral
| HexIntegerLiteral
| OctalIntegerLiteral
|
| OctalIntegerLiteral ::
| 0 OctalDigit
| OctalIntegerLiteral OctalDigit
|
| *Semantics*
|
| • The MV of NumericLiteral :: OctalIntegerLiteral is the MV of
| OctalIntegerLiteral.
| • The MV of OctalDigit :: 0 is 0.
| • The MV of OctalDigit :: 1 is 1.
| • The MV of OctalDigit :: 2 is 2.
| • The MV of OctalDigit :: 3 is 3.
| • The MV of OctalDigit :: 4 is 4.
| • The MV of OctalDigit :: 5 is 5.
| • The MV of OctalDigit :: 6 is 6.
| • The MV of OctalDigit :: 7 is 7.
| • The MV of OctalIntegerLiteral :: 0 OctalDigit is the MV of OctalDigit.
| • The MV of OctalIntegerLiteral :: OctalIntegerLiteral OctalDigit is
| (the MV of OctalIntegerLiteral times Cool plus the MV of OctalDigit.

Whereas the MV is defined as follows:

| 7.8.3.
|
| A numeric literal stands for a value of the Number type. This value is
| determined in two steps: first, a mathematical value (MV) is derived from
| the literal; [...]

Without a closer look, one could then easily conclude that 08 would be
parsed as a DecimalLiteral and 077 be parsed as an OctalIntegerLiteral.
However, that possibility is explicitly excluded by the grammar:

| 7.8.3 Numeric Literals
|
| Syntax
|
| DecimalLiteral ::
| DecimalIntegerLiteral . DecimalDigitsopt ExponentPartopt
| . DecimalDigits ExponentPartopt
| DecimalIntegerLiteral ExponentPartopt
|
| DecimalIntegerLiteral ::
| 0
| NonZeroDigit DecimalDigitsopt
|
| DecimalDigits ::
| DecimalDigit
| DecimalDigits DecimalDigit
|
| DecimalDigit :: one of
| 0 1 2 3 4 5 6 7 8 9
|
| NonZeroDigit :: one of
| 1 2 3 4 5 6 7 8 9

So if e.g. +"08" (or 0Cool resulted in 8, but +"077" (or 077) resulted in 63,
then this behavior could only be one backed up by

| 2 Conformance
|
| [...] A conforming implementation of ECMAScript is permitted to support
| program and regular expression syntax not described in this specification.

Which would be precisely the reason why I would use parseInt(..., 10) here.

Incidentally, Firefox 2.0.0.6 gives

| Warning: 08 is not a legal ECMA-262 octal constant

> Javascript lacks specific syntax for creating a Date Object of a given
> Ordinal Date;

Define "Ordinal Date". If you mean something like the number of
milliseconds since the beginning of the UNIX era, then

new Date(timestamp)

where timestamp is that number, works in JavaScript (and JScript, Opera
ECMAScript and KJS), and is specified in ES3:

| 15.9.3.2 new Date (value):
|
| The [[Prototype]] property of the newly constructed object is set to the
| original Date prototype object, the one that is the initial value of
| Date.prototype (section 15.9.4.1).
|
| The [[Class]] property of the newly constructed object is set to "Date".
|
| The [[Value]] property of the newly constructed object is set as follows:
|
| 1. Call ToPrimitive(value).
| 2. If Type(Result(1)) is String, then go to step 5.
| 3. Let V be ToNumber(Result(1)).
| 4. Set the [[Value]] property of the newly constructed object
| to TimeClip(V) and return.
| 5. [...]

Whereas the [[Value]] property of a Date object is defined implicitly as
follows:

| 15.9.1.1 Time Range
|
| Time is measured in ECMAScript in milliseconds since 01 January, 1970 UTC.
| Leap seconds are ignored. It is assumed that there are exactly 86,400,000
| milliseconds per day. ECMAScript number values can represent all
^^^^^^
| integers from –9,007,199,254,740,991 to 9,007,199,254,740,991; this range
| suffices to measure times to millisecond precision for any instant that is
| within approximately 285,616 years, either forward or backward, from 01
| January, 1970 UTC.
|
| The actual range of times supported by ECMAScript Date objects is slightly
| smaller: exactly –100,000,000 days to 100,000,000 days measured relative
| to midnight at the beginning of 01 January, 1970 UTC. This gives a range
| of 8,640,000,000,000,000 milliseconds to either side of 01 January, 1970
| UTC.
|
| The exact moment of midnight at the beginning of 01 January, 1970 UTC is
| represented by the value +0.


PointedEars
Back to top
Dr J R Stockton

External


Since: May 20, 2007
Posts: 386



(Msg. 19) Posted: Fri Aug 10, 2007 9:04 pm
Post subject: Re: adding to a ddmmyyyy date
Archived from groups: per prev. post (more info?)

In comp.lang.javascript message <46BC1351.8030705.TakeThisOut@PointedEars.de>, Fri,
10 Aug 2007 09:27:13, Thomas 'PointedEars' Lahn <PointedEars.TakeThisOut@web.de>
posted:
>Dr J R Stockton wrote:

>> ... That seems compatible with ISO/IEC 16262 B.1.

>I don't know what ISO/IEC 16262 B.1 says (I won't spend the money required
>in order to read it),

Since it is available free of charge in PDF, that seems rather
unreasonable of you. As the PDF is linked from the ISO site, one can
presume that it is legitimate. A well-maintained FAQ would have a link
to it by now; I have arranged that the URL is easily enough found,
though there's a plain route to it from the ISO page about 16262.

It does not use the same font as the ECMA one, so there's a choice.

It does, however, only have one section 15.9.1.9.



If, before reappearing here, you had read all that had been posted here
since you departed (and reading ancient material has been your forte),
you would have known most of that.



>> Javascript lacks specific syntax for creating a Date Object of a given
>> Ordinal Date;
>
>Define "Ordinal Date". If you mean something like the number of
>milliseconds since the beginning of the UNIX era, then

It is defined in ISO 8601, which is IIRC released as an EN and possibly
a DIN. Alas, 8601 is AFAIK not free (unlike 8602); but the definition
is easily found by Google.

If you had not snipped the rest of that sentence of mine, I would not
have had to repeat that it went
>> ... it does not need any, since new Date(YYYY, 0, DDD) suffices.

From that, you should be able to deduce what an Ordinal Date is. The
examples that followed would have confirmed a correct hypothesis.


It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<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.
Back to top
Dr J R Stockton

External


Since: May 20, 2007
Posts: 386



(Msg. 20) Posted: Wed Aug 15, 2007 4:40 pm
Post subject: Re: adding to a ddmmyyyy date
Archived from groups: per prev. post (more info?)

In comp.lang.javascript message <fZwtc$lfTMvGFw5W@invalid.uk.co.demon.me
rlyn.invalid>, Fri, 10 Aug 2007 21:04:47, Dr J R Stockton
<jrs.DeleteThis@merlyn.demon.co.uk> posted:
>In comp.lang.javascript message <46BC1351.8030705.DeleteThis@PointedEars.de>, Fri,
>10 Aug 2007 09:27:13, Thomas 'PointedEars' Lahn <PointedEars.DeleteThis@web.de>
>posted:
>>Dr J R Stockton wrote:

>>> Javascript lacks specific syntax for creating a Date Object of a given
>>> Ordinal Date;
>>
>>Define "Ordinal Date". If you mean something like the number of
>>milliseconds since the beginning of the UNIX era, then
>
>It is defined in ISO 8601, which is IIRC released as an EN and possibly
>a DIN. Alas, 8601 is AFAIK not free (unlike 8602); but the definition
>is easily found by Google.

Correction : I had forgotten that ISO 8601:2004 was in fact available
free in PDF, from ISO, <http://isotc.iso.org/livelink/livelink?func=ll&o
bjId=4020763&objAction=browse&sort=name> probably; and from OMG -- links
are on my site, but I forget which I actually used. It seems that ISO
do allow one to pay for the paper version and for the PDF, if one so
wishes.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
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.
Back to top
Thomas 'PointedEars' Lahn

External


Since: Sep 05, 2004
Posts: 3405



(Msg. 21) Posted: Wed Aug 22, 2007 1:53 pm
Post subject: Re: adding to a ddmmyyyy date
Archived from groups: per prev. post (more info?)

Dr J R Stockton wrote:
> [...] Thomas 'PointedEars' Lahn [...] posted:
>> Dr J R Stockton wrote:
>>> ... That seems compatible with ISO/IEC 16262 B.1.
>
>> I don't know what ISO/IEC 16262 B.1 says (I won't spend the money required
>> in order to read it),
>
> Since it is available free of charge in PDF, that seems rather
> unreasonable of you. As the PDF is linked from the ISO site, one can
> presume that it is legitimate. [...]

Thanks. Either I have overlooked it all the time, or they have added that
recently. IIRC there was no such link last time I checked.

JFTR: ISO/IEC 16262, Appendix B.1 and subsection 7.8.3, say the same here as
ECMA-262, Appendix B.1 and subsection 7.8.3, do. Therefore, I repeat what
you omitted from my posting (without marking the omission):

>> So if e.g. +"08" (or 0Cool resulted in 8, but +"077" (or 077) resulted in
>> 63, then this behavior could only be one backed up by
>>
>> | 2 Conformance
>> |
>> | [...] A conforming implementation of ECMAScript is permitted to support
>> | program and regular expression syntax not described in this
>> | specification.
>>
>> Which would be precisely the reason why I would use parseInt(..., 10)
>> here.
>>
>> Incidentally, Firefox 2.0.0.6 gives
>>
>> | Warning: 08 is not a legal ECMA-262 octal constant


PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Back to top
dhtmlkitchen

External


Since: Jul 05, 2007
Posts: 41



(Msg. 22) Posted: Thu Aug 23, 2007 11:43 pm
Post subject: Re: adding to a ddmmyyyy date
Archived from groups: per prev. post (more info?)

On Aug 8, 12:16 am, ginajohnst <ginajoh... RemoveThis @gmail.com> wrote:
> Hi All.
>
> I'm having a problem adding days to a date.
>
> My date is in the string format dd/mm/yyyy eg. 23/08/2007 in my
> form field.
>
> I can't work out how to add 50 days to that date and then write it to
> another form field.
>
I'll try a more explicit approach.

The first step is to add 50 days to the date object.

// get the date.
var date = new Date();
var dayOfMonth = date.getDate()); // This API method "getDate" should
be renamed to "getDayOfMonth".

// add 50 days.
date.setDate( dayOfMonth + 50 );

> Any help would be appreciated.
Write a unit test to verify each step.

Here is a horrible ad hoc test:
javascript:alert(new Date (new Date().setDate( new Date().getDate() +
50 ) - ( 50 * 24 * 60 * 60 * 1000 ) ) )

Garrett
Back to top
dhtmlkitchen

External


Since: Jul 05, 2007
Posts: 41



(Msg. 23) Posted: Thu Aug 23, 2007 11:48 pm
Post subject: Re: adding to a ddmmyyyy date
Archived from groups: per prev. post (more info?)

The problem appears that there is no standard way of formatting a Date
to a customized string.

It seems possible to format a Date string using a RegExp, but the Date
string cannot be guaranteed to be in a specific format.

I would like to see this added to ES4.

var s = "EEE, MMM d, yyyy"
var df = DateFormat( s );
var formattedDay df.format( new Date() ); // Thu, Aug 23, 2007.

http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html
Back to top
Thomas 'PointedEars' Lahn

External


Since: Sep 05, 2004
Posts: 3405



(Msg. 24) Posted: Fri Aug 24, 2007 2:51 am
Post subject: Re: adding to a ddmmyyyy date
Archived from groups: per prev. post (more info?)

dhtmlkitchen DeleteThis @gmail.com wrote:
> The problem appears that there is no standard way of formatting a Date
> to a customized string.
>
> It seems possible to format a Date string using a RegExp, but the Date
> string cannot be guaranteed to be in a specific format.

-v

> I would like to see this added to ES4.

While you wait for that, you might as well implement it. It is not
that difficult.

> var s = "EEE, MMM d, yyyy"
> var df = DateFormat( s );
> var formattedDay df.format( new Date() ); // Thu, Aug 23, 2007.
^
= ----------------'

> http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html

So?


PointedEars
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Back to top
Thomas 'PointedEars' Lahn

External


Since: Sep 05, 2004
Posts: 3405



(Msg. 25) Posted: Fri Aug 24, 2007 2:56 am
Post subject: Re: adding to a ddmmyyyy date
Archived from groups: per prev. post (more info?)

dhtmlkitchen.RemoveThis@gmail.com wrote:
> [...]
> date.setDate( dayOfMonth + 50 );

You are a *little* late. <Xns9986EF7F65D6Deejj99.RemoveThis@194.109.133.242>


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Back to top
Dr J R Stockton

External


Since: May 20, 2007
Posts: 386



(Msg. 26) Posted: Fri Aug 24, 2007 9:24 pm
Post subject: Re: adding to a ddmmyyyy date
Archived from groups: per prev. post (more info?)

In comp.lang.javascript message <1187912891.521371.67400.DeleteThis@z24g2000prh.goo
glegroups.com>, Thu, 23 Aug 2007 23:48:11, "dhtmlkitchen@gmail.com"
<dhtmlkitchen.DeleteThis@gmail.com> posted:
>The problem appears that there is no standard way of formatting a Date
>to a customized string.
>
>It seems possible to format a Date string using a RegExp, but the Date
>string cannot be guaranteed to be in a specific format.
>
>I would like to see this added to ES4.
>
>var s = "EEE, MMM d, yyyy"
>var df = DateFormat( s );
>var formattedDay df.format( new Date() ); // Thu, Aug 23, 2007.
>
>http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html

Since that is Java, and this is a Javascript newsgroup, ISTM that you
have a severe sagacity deficiency.


It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<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.
Back to top
Randy Webb

External


Since: Aug 24, 2004
Posts: 4981



(Msg. 27) Posted: Fri Aug 24, 2007 9:24 pm
Post subject: Re: adding to a ddmmyyyy date
Archived from groups: per prev. post (more info?)

Dr J R Stockton said the following on 8/24/2007 4:24 PM:
> In comp.lang.javascript message <1187912891.521371.67400.RemoveThis@z24g2000prh.goo
> glegroups.com>, Thu, 23 Aug 2007 23:48:11, "dhtmlkitchen@gmail.com"
> <dhtmlkitchen.RemoveThis@gmail.com> posted:
>> The problem appears that there is no standard way of formatting a Date
>> to a customized string.
>>
>> It seems possible to format a Date string using a RegExp, but the Date
>> string cannot be guaranteed to be in a specific format.
>>
>> I would like to see this added to ES4.
>>
>> var s = "EEE, MMM d, yyyy"
>> var df = DateFormat( s );
>> var formattedDay df.format( new Date() ); // Thu, Aug 23, 2007.
>>
>> http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html
>
> Since that is Java, and this is a Javascript newsgroup, ISTM that you
> have a severe sagacity deficiency.

If you had bothered to read, and comprehend, the line preceding the code
posted you would have realized some things that you are either too
arrogant or too ignorant to admit, possibly - and probably - both.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Back to top
Dr J R Stockton

External


Since: May 20, 2007
Posts: 386



(Msg. 28) Posted: Fri Aug 24, 2007 9:32 pm
Post subject: Re: adding to a ddmmyyyy date
Archived from groups: per prev. post (more info?)

In comp.lang.javascript message <1187912615.682375.96390.DeleteThis@r23g2000prd.goo
glegroups.com>, Thu, 23 Aug 2007 23:43:35, "dhtmlkitchen@gmail.com"
<dhtmlkitchen.DeleteThis@gmail.com> posted:

>Here is a horrible ad hoc test:
>javascript:alert(new Date (new Date().setDate( new Date().getDate() +
>50 ) - ( 50 * 24 * 60 * 60 * 1000 ) ) )

That will, at present, show the present date and time.

But change both instances of 50 to 130, and it will probably show you an
hour after present time, but might show the present time or an hour (or
half an hour, but that's unlikely) before present time.

Until you understand that, it would be better if you did not try to
answer Javascript date questions.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6.
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.
Back to top
dhtmlkitchen

External


Since: Jul 05, 2007
Posts: 41



(Msg. 29) Posted: Sun Aug 26, 2007 3:02 am
Post subject: Re: adding to a ddmmyyyy date
Archived from groups: per prev. post (more info?)

On Aug 23, 5:51 pm, Thomas 'PointedEars' Lahn <PointedE... RemoveThis @web.de>
wrote:
> dhtmlkitc... RemoveThis @gmail.com wrote:
> > The problem appears that there is no standard way of formatting a Date
> > to a customized string.
>
> > It seems possible to format a Date string using a RegExp, but the Date
> > string cannot be guaranteed to be in a specific format.
>
> -v
>
> > I would like to see this added to ES4.
>
> While you wait for that, you might as well implement it. It is not
> that difficult.
>

Yeah, probably less than 2 work days to write and test. toString on a
Date doesn't guarantee any format. use toUTCString() does.

>From the outset, it doesn't appear that DateFormat would require
additional classes; just RegExp, Date, String. It could probably stand
on its own, cohesively, and might be less than 20k.

How common is the need for a Date formatter?

What would be the performance impact?

What would be the risk?

What are the alternatives?

> > var s = "EEE, MMM d, yyyy"
> > var df = DateFormat( s );
> > var formattedDay df.format( new Date() ); // Thu, Aug 23, 2007.
>
> ^
> = ----------------'
>
> >http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html
>
> So?
>
It's a useful implementation with detailed documentation.

Date formatting on the server using SimpleDateFormat is reliable,
existing code. Sending a formatted date is can sometimes fulfill the
need.

However, other use cases make server side options impractical.

Personally, I would probably choose to format on the server as much as
I can, and when I can't, I would probably try the simplest thing that
could possibly work (not writing a full-featured DateFormatter unless
it were necessary).

> PointedEars
Back to top
Dr J R Stockton

External


Since: May 20, 2007
Posts: 386



(Msg. 30) Posted: Sun Aug 26, 2007 9:52 pm
Post subject: Re: adding to a ddmmyyyy date
Archived from groups: per prev. post (more info?)

In comp.lang.javascript message <1188106421.668958.202030.TakeThisOut@m37g2000prh.go
oglegroups.com>, Sun, 26 Aug 2007 05:33:41, "dhtmlkitchen@gmail.com"
<dhtmlkitchen.TakeThisOut@gmail.com> posted:

>Personally, I would probably choose to format on the server as much as
>I can, and when I can't, I would probably try the simplest thing that
>could possibly work (not writing a full-featured DateFormatter unless
>it were necessary).

Yes. Only under weird circumstances does it seem likely to be necessary
to inflict a completely versatile date formatter on everyone who
downloads a Web page.

Nowadays, I believe the default conversion of Date Object to String
gives unambiguous English. Conversion to Foreign takes a little more.

A few lines suffice to generate, for any reasonably-current date, the
ISO 8601 format YYYY-MM-DD which is understandable without ambiguity
everywhere that the Gregorian Calendar is used (USG agencies excepted).

Another to use the TLA for the month (e.g. Feb), and another one for the
TLA for the DoW (e.g. Thu).

The following, not necessarily optimum, sets S to three date forms :-

function LZ(x) { return (x<10?"0":"") + x }
M = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" ")
W = "Sun Mon Tue Wed Thu Fri Sat".split(" ")
D = new Date()
S = D.getFullYear()+'-'+LZ(D.getMonth()+1)+'-'+LZ(D.getDate())
S = D.getFullYear()+'-'+M[D.getMonth()]+'-'+LZ(D.getDate())
S += ", " + W[D.getDay()]

--
(c) John Stockton, Surrey, UK. REPLYyyww merlyn demon co uk Turnpike 6.05.
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 precede replies. Snip well. Write clearly. Mail no News.
Back to top
Display posts from previous:   
       Webmaster Forums (Home) -> Javascript
Goto page Previous  1, 2
Page 2 of 2

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum