JRS: In article <12*************@corp.supernews.com>, dated Thu, 20 Apr
2006 10:23:33 remote, seen in news:comp.lang.javascript, Captain Dondo
<ya*@NsOeSiPnAeMr.com> posted :
I have a value representing seconds since epoch (the number of seconds
since midnight Jan 1, 1970).
That's unreasonable or inadequately described; one almost always has
seconds since 1970-01-01 00:00:00 UTC (really GMT), where the TLA is
important. Also, midnight usually means the end of the day - consider
"I'll see you tomorrow, at midnight".
I want to disply this as Month, Day, and Year: MMM-DD-YYYY.
Silly format.
Month needs only two digits, and one writes Mon for the TLA.
I've read about the Date() object but I am a bit confused.... How do I
get the year given seconds since epoch?
But did you read the newsgroup FAQ, as posted Mon/Fri??
You can use
new Date(sec*1e3).getFullYear()
or new Date(sec*1e3).getUTCFullYear()
depending on requirement. If you want the year in a location other than
"Greenwich" or user's local, that's harder, but can always be done if
the TZ string is known - see in my js-date5.htm .
Then the date in proper standard form can be got, for example, with code
(in include1.js, shown in js-nclds.htm) such as resulted in :-
function anonymous() {
/* Date.ISOlocaldateStr YYYY-MM-DD */
with (this)
return getFullYear()+'-'+LZ(getMonth()+1)+'-'+LZ(getDate())
}
or with such as
with (Dobj)
S = String((getFullYear()*100+getMonth()+1)*100+getDat e()).
replace(/(....)(..)(..)/, "$1-$2-$3")
If you must have MMM-DD-YYYY, start with YYYY-MM-DD and adapt it.
-----------
Note to All : my PC was reluctant to boot today. If I seem to vanish,
such could be the cause.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of 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.