简体   繁体   中英

How get the next and previuos day in java Calendar?

如何在Java日历中获得第二天和上一天?

You can either user the Calendar class like icyrock said or use Joda Time. You can see examples of Joda time here . I recommend using Joda time highly.

Jodatime code snippet:

 DateTime dt = new DateTime(date); //the date you want to add days to
 Date addedDate = dt.plusDays(daysToAdd).toDate(); //the added days date
 Date subtractedDate = dt.minusDays(daysToMinus).toDate(); //the subtracted days date
Calendar.add(Calendar.DATE, -1)
Calendar.add(Calendar.DATE, 1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM