我有一个格式为
最佳答案
我会稍微重写这些答案。
你可以使用
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);
获得与使用日历计算的结果相同的结果。
关于java - 如何在java中获取以前的日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2458049/