Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript get current day and month issue

Tags:

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?

like image 339
Hidalgo Avatar asked Apr 18 '14 19:04

Hidalgo


1 Answers

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)

like image 135
Venkata Krishna Avatar answered Oct 16 '22 19:10

Venkata Krishna