我会重写这些答案.

您可以使用

DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");

// Get a Date object from the date string

Date myDate = dateFormat.parse(dateString);

// this calculation may skip a day (Standard-to-Daylight switch)...

//oneDayBefore = new Date(myDate.getTime() - (24 * 3600000));

// if the Date->time xform always places the time as YYYYMMDD 00:00:00

// this will be safer.

oneDayBefore = new Date(myDate.getTime() - 2);

String result = dateFormat.format(oneDayBefore);

获得与使用日历计算的结果相同的结果.

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐