JRS: In article <kc******************************@comcast.com>, dated
Fri, 16 Jun 2006 15:45:02 remote, seen in news:comp.lang.javascript,
Randy Webb <Hi************@aol.com> posted :
O.B. said the following on 6/16/2006 3:22 PM: I'm trying to convert the current year into a 2-digit format. Since
getYear returns 106, I'm trying to perform a substring of getFullYear()
getYear does not necessarily return 106; it can return 2006 or 6,
depending on browser.
On the Internet, getYear should only be used if either the year will
be in 1900..1999 or it is effectively followed by code restricting the
value to 0..99 or "00".."99".
with no luck. What am doing wrong?
Don't rely on luck; read the newsgroup FAQ, carefully.
currentTime = new Date()
var result = "FY" + currentTime.getFullYear().substring(2, 4)
var result = "FY" + (currentTime.getFullYear())%100;
Or, just use getYear and do the same thing with %100
The OP, in Subject and Body, calls for a 2-digit format. Your code, for
10% of years including around now, gives 1-digit.
R = "FY" + String(currentTime.getFullYear()).substring(2, 4)
R = ("FY" + currentTime.getFullYear()).replace(/(..)..(..)/, "$1$2")
R = "FY" + LZ(currentTime.getYear()%100)
--
© 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.