Using the javascript code below I get month = 3, day = 5, y = 2014. Of course I expect month 4 and day 18.
var TodayDate = new Date();
var d = TodayDate.getDay();
var m = TodayDate.getMonth();
var y = TodayDate.getFullYear();
What am I doing wrong?
you have to use getMonth() + 1
to get month (zero-index based) because javascript implementation followed JAVA & that is how java.util.Date
did it.
getDay()
- gives you 5
for today being Friday(6th Day of the week. Sunday 0 to Saturday 6)
getDate()
- gives you 18
(today's date)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With