How to get day of the month?

后端 未结 9 1699
南笙
南笙 2020-11-30 05:48

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.

9条回答
  •  清歌不尽
    2020-11-30 05:50

    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.

提交回复
热议问题