首页>代码>java获得一周前的日期>/1002158206256128.java
import java.text.SimpleDateFormat;
import java.util.Date;




public class ttt {
	/**
	 * @Title: lastWeek
	 * @return
	 * @Description: 获得一周前的日期
	 */
	public static String lastWeek() {
		Date date = new Date();
		int year = Integer.parseInt(new SimpleDateFormat("yyyy").format(date));
		int month = Integer.parseInt(new SimpleDateFormat("MM").format(date));
		int day = Integer.parseInt(new SimpleDateFormat("dd").format(date)) - 6;

		if (day < 1) {
			month -= 1;
			if (month == 0) {
				year -= 1;
				month = 12;
			}
			if (month == 4 || month == 6 || month == 9 || month == 11) {
				day = 30 + day;
			} else if (month == 1 || month == 3 || month == 5 || month == 7
					|| month == 8 || month == 10 || month == 12) {
				day = 31 + day;
			} else if (month == 2) {
				if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
					day = 29 + day;
				else
					day = 28 + day;
			}
		}
		String y = year + "";
		String m = "";
		String d = "";
		if (month < 10)
			m = "0" + month;
		else
			m = month + "";
		if (day < 10)
			d = "0" + day;
		else
			d = day + "";
		return y + "-" + m + "-" + d;
	}
}
最近下载更多
最近浏览更多
刘孟彪  LV9 2020年12月30日
AhouYa 2020年8月7日
暂无贡献等级
kong.yee  LV40 2020年6月9日
RinkaOvO  LV2 2020年4月24日
lw19900921  LV25 2018年9月20日
故事_sun  LV26 2018年4月20日
走掉的旋律  LV8 2018年1月3日
梁华荣  LV1 2017年12月13日
duodada  LV2 2017年6月8日
子言雨石 2017年4月6日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友