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

javascript to display current date (and back dates)

P: n/a
Hello all,

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

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

Which would be two days earlier than today's date, but in keeping with
the same format.

Any help on this would be greatly appreciated.
KG
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <d8********************************@4ax.com>, Kevin Gibbons
<kevin@<NOSPAM>kgibbons.com> enlightened us with...
Hello all,

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


If you're familiar with java's SimpleDateFormat class, you might like
this author's javascript version.

http://www.mattkruse.com/javascript/date/source.html

--
--
~kaeli~
Reading while sunbathing makes you well red.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2

P: n/a
Kevin Gibbons <kevin@ wrote:
I'm looking for a simple
javascript that will display the date as such:

May 17

I would also like the ability to backdate by one day, two days,
etc.. So the next date might look as such:

May 15
Any help on this would be greatly appreciated.


m=
["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","S ep","Oct","Nov","Dec"];
n=new Date();
today=m[n.getMonth()] +" "+n.getDate();
alert(today);

n.setDate(n.getDate()-2);
dayBeforeYesterday=m[n.getMonth()]+" " +n.getDate();
alert(dayBeforeYesterday);

Something like that.
Mick
Jul 23 '05 #3

P: n/a
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.
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.