ypc
2012-10-12 08:33:03
java 获得一月前的日期
日期获得 一个月前的
package com.zuidaima.test; import java.text.SimpleDateFormat; import java.util.Date; public class ttt { /** * @Title: lastWeek * @return * @Description: 获得一月前的日期 */ public static void main(String[] args) { System.out.println(lastMonth()); } public static String lastMonth() { Date date = new Date(); int year = Integer.parseInt(new SimpleDateFormat("yyyy").format(date)); int month = Integer.parseInt(new SimpleDateFormat("MM").format(date)) - 1; int day = Integer.parseInt(new SimpleDateFormat("dd").format(date)); if (month == 0) { year -= 1; month = 12; } else if (day > 28) { if (month == 2) { if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) { day = 29; } else day = 28; } else if ((month == 4 || month == 6 || month == 9 || month == 11) && day == 31) { day = 30; } } 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; } }
由最代码官方编辑于2013-12-20 18:15:20
猜你喜欢
- 【猪猪-后端】Joda开源扩展插件,神马日期工具类都是浮云!!Demo下载运行即可查看,注释齐全,真心好用,分享大家。
- java高仿微博日期显示格式化,日期辅助工具类
- java获得一周前的日期
- java日期操作工具类
- java面向对象思想算出当前阳历日期的下一秒
- java自定义日期类型操作转换
- java常用日期时间工具类大全
- java时间操作工具类得到本周周一,周末,本月1号,月末日期
- 新浪微博时间格式化java工具类,实现几分钟前,几小时前,几天前
- java计算两个日期之间的天数,并格式化返回天小时分钟的代码片段
- JAVA新手写的日期工具类
- java几秒前,几分钟前,几小时前,几天前,几月前,几年前的实现
请下载代码后再发表评论


骑着猪猪去逛街 LV32
2013年12月18日
ilcqr@126.com LV1
2013年9月3日

2196316269 LV10
2021年2月25日
kong.yee LV40
2020年6月9日
wei112233 LV15
2020年4月21日
数据库1 LV12
2019年8月24日
hyaxzz LV5
2019年1月2日
lw19900921 LV25
2018年9月20日
727103517
2018年2月7日
暂无贡献等级
mmmm7777 LV8
2017年8月31日
nekocon LV1
2017年4月7日
vanish LV1
2016年12月7日