Hello,I have problem because I cannot find the solution with 2 digits for year in javascript. I use this:I would like help.Code:var result = today.getFullYear().substring(2, 4);
Hello,I have problem because I cannot find the solution with 2 digits for year in javascript. I use this:I would like help.Code:var result = today.getFullYear().substring(2, 4);
The getFullYear() method returns a number. The substring() method can only be applied to a string. The getFullYear value needs to be type converted to a string before using a string method on it, so:
Or (probably more efficient):Code:var result = today.getFullYear().toString(10).substring(2, 4);
Note: In the second exampleCode:var result =(today.getFullYear()+ '').substring(2, 4);''is an empty string delimited by single quotes ('). There's nothing inside, not even a space. If in doubt, copy and paste it.
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Dimi Cost (04-06-2011)
Bookmarks