How to calculate the number of days separated between the two dates? Usage of Calendar

xiaoxiao2021-03-06  73

// First define a Calendar, you must institerate using getInstance ()

Calendar acalendar = calendar.getinstance ();

// Setting time is

2004

year

8

month

30

day

// Inside the wild can be directly inserted into the Date type

Aclendar.Settime (2004, Calendar.Auguest, 30);

/ / Which day is calculated this date?

INT day1 = aclendar.get (calendar.day_of_year);

Aclendar.Settime (2004, Calendar.Auguest, 30);

INT day2 = aclendar.get (calendar.day_of_year);

// Discover the two days of separation

SetNumberOfDays (day2-day1);

// Add 1 unit to the year, can increase the month, date

Aclendar.add (Calendar.Year, 1);

转载请注明原文地址:https://www.9cbs.com/read-109472.html

New Post(0)