Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get day of the month?

Tags:

java

android

I am trying to retrieve which day of the month it is.

Such as today is August 29,2011.

What i would like to do is just get the days number such as 29, or 30. Which ever day of the month it is.

How would i go about doing this?

like image 447
yoshi24 Avatar asked Aug 29 '11 04:08

yoshi24


People also ask

How do you figure out the day of the month?

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 to get the day of the month JavaScript?

getDate() getDate() is an date method in JavaScript, which is used to return the day of the month (between 1 to 31) for the specified date. This method does not have any parameters.


2 Answers

You'll want to do get a Calendar instance and get it's day of month

Calendar cal = Calendar.getInstance(); int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);  String dayOfMonthStr = String.valueOf(dayOfMonth); 

You can also get DAY_OF_WEEK, DAY_OF_YEAR, DAY_OF_WEEK_IN_MONTH, etc.

like image 109
hooked82 Avatar answered Oct 01 '22 05:10

hooked82


The following method would help you in finding day of any specified date :

public static int getDayOfMonth(Date aDate) {     Calendar cal = Calendar.getInstance();     cal.setTime(aDate);     return cal.get(Calendar.DAY_OF_MONTH); } 
like image 41
Gaurav Naugain Avatar answered Oct 01 '22 03:10

Gaurav Naugain