JAVA比较日期前后的方法

在java中要比较日期的前后

代码如下

				SimpleDateFormat sdf =   new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				String beginTimeString="2017-03-24 08:00:00";

				String endTimeString="2017-03-27 08:00:00";

				String nowtimeString =sdf.format(new Date());
				Date beginTimeDate = sdf.parse( activitybeginTimeString );
				Date endTimeDate = sdf.parse( activityendTimeString );
				Date nowtimeTimeDate = sdf.parse( nowtimeString );
				System.out.println("活动开始时间"+beginTimeDate);
				System.out.println("活动结束时间"+endTimeDate);
				System.out.println("当前时间"+nowtimeTimeDate);
if ( (nowtimeTimeDate.before(activityendTimeDate))&&((nowtimeTimeDate.after(activitybeginTimeDate))) ){ 
					  System.out.println("活动期内");}else{
System.out.println("活动期外");
}

判断当前日期是否处于制定日期内



你可能感兴趣的:(JAVA)