码迷,mamicode.com
首页 > 其他好文 > 详细

DateUtil

时间:2016-12-26 18:41:56      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:instance   class   boolean   format   time   simple   div   calendar   bool   

1、比较两个日期是否是同一天

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

Date lastRecordTimeD = sdf.parse(lines[2]);

Calendar lastRecordTimeCal = new GregorianCalendar();

lastRecordTimeCal.setTime(lastRecordTimeD);

Calendar nowTime = Calendar.getInstance();

Calendar tempDate = (Calendar) nowTime.clone();

tempDate.set(Calendar.YEAR, lastRecordTimeCal.get(Calendar.YEAR));
tempDate.set(Calendar.MONTH, lastRecordTimeCal.get(Calendar.MONTH));
tempDate.set(Calendar.DAY_OF_MONTH,lastRecordTimeCal.get(Calendar.DAY_OF_MONTH));

//是否是同一天
boolean sameDay = false;

if (nowTime.equals(tempDate)) {
    sameDay = true;
}

 

DateUtil

标签:instance   class   boolean   format   time   simple   div   calendar   bool   

原文地址:http://www.cnblogs.com/orco/p/6223183.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!