📜  在 AndroidStudio 中添加未来日期 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:29.500000             🧑  作者: Mango

代码示例1
String dt = "2012-01-04";  // Start date
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
try {
    c.setTime(sdf.parse(dt));
} catch (ParseException e) {
    e.printStackTrace();
}
c.add(Calendar.DATE, 40);  // number of days to add, can also use Calendar.DAY_OF_MONTH in place of Calendar.DATE
SimpleDateFormat sdf1 = new SimpleDateFormat("MM-dd-yyyy");
String output = sdf1.format(c.getTime());