小视频源码,判断选择的日期是否是今天、本周、本月实现相关的代码
public static boolean isThisWeek(long time) {
Calendar calendar = Calendar.getInstance();
int currentWeek = calendar.get(Calendar.WEEK_OF_YEAR);
calendar.setTime(new Date(time));
int paramWeek = calendar.get(Calendar.WEEK_OF_YEAR);
if(paramWeek==currentWeek){
return true;
}
return false;
}
**//判断选择的日期是否是今天**
public static boolean isToday(long time)
{
return isThisTime(time,"yyyy-MM-dd");
}
//判断选择的日期是否是本月
public static boolean isThisMonth(long time)
{
return isThisTime(time,"yyyy-MM");
}
private static boolean isThisTime(long time,String pattern) {
Date date = new Date(time);
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
String param = sdf.format(date);//参数时间
String now = sdf.format(new Date());//当前时间
if(param.equals(now)){
return true;
}
return false;
}
以上就是 小视频源码,判断选择的日期是否是今天、本周、本月实现相关的代码,更多内容欢迎关注之后的文章