How to get the last date of a month on Android

Asked 1 years ago, Updated 1 years ago, 48 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.