Tuesday, March 10, 2015
Funny javascript date function
var t = new Date;
var day = t.getDate(); // returns the actual day of the month; like 1-31
var Month = t.getMonth(); // returns the 0-based index of the month; like 0-11
So to get the real month value, you need to do
var Month = t.getMonth()+1;
Now Im sure theres a whole lot smart reasons for doing it like this. But its damn not logical. Why are days not 0-based? Or years? I guess its just to keep things complicated.
Anyway, then comes the getYear() and getFullYear(). Why did they ever create the method getYear()? I guess its to have me enter a blog post. :-)
Labels:
date,
function,
funny,
javascript
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.