+ 2
javascript Date function is not working properly for me
var d = new Date(); var hours = d.getHours();//hours is equal to the current hour var min=d.getMinutes(); var sec=d.getSeconds(); var millisec=d.getMilliseconds(); var year=d.getFullYear(); var month=d.getMonth(); var date=d.getDate(); var day=d.getDay(); document.write(hours+":"+min+":"+sec+":"+millisec+" "+day+"/"+date+"/"+month+"/"+year); output: 7:59:56:87 2/20/1/2018 day method is not working ,and mont method showing "1" and day method showing my current month
2 Answers
+ 3
getDay() returns a number from 0-6(days of the week where 0 is Sunday)
getDate() returns a number from 1-31(day of the month)
getMonth() returns a number from 0-11(months of the year where 0 is January) .
The code is fine.
For better reference:
https://www.w3schools.com/jsref/jsref_obj_date.asp
+ 3
ok , something wrong with the month,may be it's my system problem , thanks for answering . now I understand the output..