Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get number of day in javascript date object

//27 <- today day number
new Date().getDay() = new Date().getUTCDay() //<- 5 (friday)? what?

Do I have to parse the result with .toString() or use something like YUI.Date.format()?

like image 968
puchu Avatar asked May 27 '11 14:05

puchu


People also ask

How do you know if a month has 30 or 31 days Javascript?

JavaScript getDate() Method: This method returns the number of days in a month (from 1 to 31) for the defined date. Return value: It returns a number, from 1 to 31, representing the day of the month.

What is getDate () in Javascript?

Javascript date getDate() method returns the day of the month for the specified date according to local time. The value returned by getDate() is an integer between 1 and 31.

Is the Javascript date object always one day off?

@Codo - yes, good reply. ECMA-262 15.9. 1.15 applies. The OP should use "2011-09-24T20:00:00-04:00" or similar.


2 Answers

You're looking for .getDate():

new Date().getDate();

.getDay() returns the day number 0 (Sunday) to 6 (Saturday).

like image 74
Andy E Avatar answered Oct 30 '22 18:10

Andy E


The one you are looking for is .getDate(), not .getDay()

Date Object Reference

like image 34
ShaneBlake Avatar answered Oct 30 '22 18:10

ShaneBlake