我是靠谱客的博主 美丽哑铃,这篇文章主要介绍获得指定日期的前几天日期,现在分享给大家,希望可以做个参考。

 /**
* 获得指定日期的前几天日期
*
* @param specifiedDay 指定日期
* @param pattern
需要返回的日期格式,如yyyy-MM-dd
* @param before
前几天
* @return String
*/
public static String getSpecifiedDayBefore(String pattern, String specifiedDay, int before) {
Calendar c = Calendar.getInstance();
Date date;
String dayBefore = "";
try {
date = new SimpleDateFormat(pattern).parse(specifiedDay);
c.setTime(date);
int day = c.get(Calendar.DATE);
c.set(Calendar.DATE, day - before);
dayBefore = new SimpleDateFormat(pattern).format(c.getTime());
} catch (Exception e) {
//todo
} finally {
return dayBefore;
}
}

最后

以上就是美丽哑铃最近收集整理的关于获得指定日期的前几天日期的全部内容,更多相关获得指定日期内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(102)

评论列表共有 0 条评论

立即
投稿
返回
顶部