您的位置:首页 > 其它

判断当前日期是否在指定的开始日期和结束日期之间

2017-11-13 14:47 381 查看
/**
* 判断当前日期是否在指定的开始日期和结束日期之间
*
* @param bDate 开始时间
* @param eDate 结束时间
* @return 在时间段内返回true 其他返回false
*/
public static boolean inDate(String bDate, String eDate) {
try {
Calendar calendar = Calendar.getInstance();
calendar.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(bDate));
Long bDateMillis = calendar.getTimeInMillis();
calendar.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(eDate));
calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) + 1);
Long eDateMillis = calendar.getTimeInMillis();
Long nowDateMillis = System.currentTimeMillis();
if (nowDateMillis >= bDateMillis && nowDateMillis < eDateMillis) {
return true;
} else {
return false;
}
} catch (Exception e) {
return false;
}
}




                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐