简体   繁体   English

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

[英]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. 您可以像icyrock一样使用Calendar类,也可以使用Joda Time。 You can see examples of Joda time here . 您可以在此处查看Joda时间的示例。 I recommend using Joda time highly. 我建议高度使用Joda时间。

Jodatime code snippet: Jodatime代码段:

 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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