DateFormat formatter = new SimpleDateFormat("yyyy/MM");
Date nowMonth = new Date();
Date agoMonth = new Date();
Date lateMonth = new Date();
nowMonth = formatter.parse("2010/03");
agoMonth = formatter.parse("2010/01");
lateMonth = formatter.parse("2010/04");
//然后就可判断各月份大小 判断结果中间省略
if(nowMonth.getTime() < agoMonth.getTime() ) {
......
}
Date nowMonth = new Date();
Date agoMonth = new Date();
Date lateMonth = new Date();
nowMonth = formatter.parse("2010/03");
agoMonth = formatter.parse("2010/01");
lateMonth = formatter.parse("2010/04");
//然后就可判断各月份大小 判断结果中间省略
if(nowMonth.getTime() < agoMonth.getTime() ) {
......
}
本文介绍了一种使用SimpleDateFormat类来解析并比较不同月份日期大小的方法。通过实例演示了如何设置日期格式,以及如何利用getTime()方法来进行月份之间的大小比较。
1086

被折叠的 条评论
为什么被折叠?



