How to get the last date of a month on Android

Asked 2 years ago, Updated 2 years ago, 60 views

I'm implementing a calendar right now and I'd like to get the last day of the month. on the code I don't know how to do this at all, but please teach me.

android calendar

2022-09-22 15:08

1 Answers

You can use the Calendar method.

public static void main(String[] args) {
    Calendar cal = Calendar.getInstance();
        System.out.println(cal.get(Calendar.MONTH)+1+"Month");
    System.out.println ("Last Day:"+cal.getMaximum(Calendar.DAY_OF_MONTH)));
}

where cal.getMaximum(Calendar.DAY_OF_MONTH) You can use it where you want it.


2022-09-22 15:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.