From: Stefan Weiss on
On 03/08/10 10:10, dhtml wrote:
> c

Please remember to declare your variables:

var c;


--
stefan
From: Dr J R Stockton on
In comp.lang.javascript message <vd7q8ibg.fsf(a)gmail.com>, Wed, 4 Aug
2010 18:16:03, Lasse Reichstein Nielsen <lrn.unread(a)gmail.com> posted:

>dhtml <dhtmlkitchen(a)gmail.com> writes:
>
>> On Jul 30, 7:45 am, Asen Bozhilov <asen.bozhi...(a)gmail.com> wrote:
>
>>> return (yyyy + "-" + mm + "-" + dd).replace(/\b1/g, '');
>
>I think RegExp replace is a little heavy-duty for something like this.
>How about
> return String(yyyy).substring(1) + "-" +
> String(mm).substring(1) + "-" +
> String(dd).substring(1);
>?

One should not expect the date formatter to be called in isolation. The
proper way must IMHO be to have a rather general padding function or a
set of moderately general ones, such as

function LZ(n) { return (n!=null&&n<10&&n>=0?"0":"") + n }

function SpcsTo(S, L) { S += ""
while (S.length<L) S = " " + S ; return S }

function ZeroTo(S, L) { S += ""
while (S.length<L) S = "0" + S ; return S }

function ToNd(X, N) { // developed from ZeroTo
if (X<0) return "-" + ToNd(-X, N)
X += "" ; while (X.length<N) X = "0" + X ; return X }

function ChrsTo(S, L, C) {
for (var i = String(S).length ; i < L ; i++) S = C + S
return S }

function TailTo(X, Ch, L) { var S = String(X)
while (S.length < L) S += Ch
return S }

(or, if preferred, Methods of Number) and then to write something like

return ZeroTo(yyyy, 4) + "-" + LZ(mm) + "-" + LZ(dd)

Note that LZ gives an appropriate result for any possible value of n
including NaN (except for those who want to see '-0').

Now there is for example an obvious way (for almost all continents) of
formatting time with LZ; and formatting ww in standard Week Numbers, and
ddd in Ordinal Dates and integer degrees or grads (though I also have a
LZZ for that),

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <URL:http://www.merlyn.demon.co.uk/> - FAQish topics, acronyms, & links.
Proper <= 4-line sig. separator as above, a line exactly "-- " (RFCs 5536/7)
Do not Mail News to me. Before a reply, quote with ">" or "> " (RFCs 5536/7)
 | 
Pages: 1
Prev: elavil 10 mg
Next: side effects of loxitane