JRS: In article <d8********************************@4ax.com>, seen in
news:comp.lang.javascript, Kevin Gibbons <kevin@?.com> posted at Mon, 17
May 2004 01:12:46 :
I've browsed through past usenet archives, but can't seem to come
across quite the javascript I'm looking for. I'm looking for a simple
javascript that will display the date as such:
May 17
Did you not find the FAQ of this newsgroup?
Did you not find the FAQ of this newsgroup helpful?
So basically, just displaying the current month and the current date.
But I would also like the ability to backdate by one day, two days,
etc.. So the next date might look as such:
May 15
Not a good example; is May the name of the month, or the three-letter
abbreviation therefor? A week earlier, should that be May 5 or May 05 ?
Should the date be local-to-user, local-to-server, or GMT? I assume the
former, and that the user's computer's clock can be believed.
A = ["Jan", "Feb", "Mar", "Apr", "May", ..., "Dec"] // or "January" ..
D = new Date()
ITIS = A[D.getMonth()] + " " + D.getDate()
D.setDate(D.getDate() - 2)
TWAS = A[D.getMonth()] + " " + D.getDate()
That gives May 5 style; for May 05 use LZ(D.getDate()) with
function LZ(x) { return (x<0||x>=10?"":"0") + x }
<FAQENTRY>
IMHO, typing would be saved if LZ were in the FAQ.
</FAQENTRY>
The following can be used for the current date IF you are assured that
the first occurrence of <word> <space> <number> in String(new Date())
will ALWAYS be what you want :-
ITIS = String(new Date()).match(/(\w+ \d+)/)[1]
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for 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.