Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get year/month/day from a date object?

alert(dateObj) gives Wed Dec 30 2009 00:00:00 GMT+0800

How to get date in format 2009/12/30?

like image 756
user198729 Avatar asked Jan 06 '10 13:01

user198729


People also ask

How do you find the month and year from a date object?

The Date object methods getDate() , getMonth() , and getFullYear() can be used to retrieve day, month, and full year from a date object in JavaScript. Note that the getDate() , getMonth() , and getFullYear() methods return the date and time in the local time zone of the computer where the code is running.

How do you find the day of the month from the date object?

To get the day of the month, use the getDate() method. 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.

How do you find the year of a date object?

The getYear() method is used to get the year of a given date according to local time. The getYear() method returns the year minus 1900; thus: * For years above 2000, the value returned by getYear() is 100 or greater. For example, if the year is 2009, getYear() returns 109.


1 Answers

var dateObj = new Date(); var month = dateObj.getUTCMonth() + 1; //months from 1-12 var day = dateObj.getUTCDate(); var year = dateObj.getUTCFullYear();  newdate = year + "/" + month + "/" + day; 

or you can set new date and give the above values

like image 60
Hiyasat Avatar answered Oct 25 '22 22:10

Hiyasat