有的时候,需要拿数据库里面的时间,比较是否为当前,时间
现在在这里介绍一个简单粗暴的方法
//判定时间
Date useTime = myCharacterDto.getUseTime();
Date date = new Date();
int year = date.getYear();
int month = date.getMonth();
int day = date.getDay();
int day1 = useTime.getDay();
int month1 = useTime.getMonth();
int year1 = useTime.getYear();
if (year==year1 & month1==month & day==day1){
//两者时间相等,所以在这里执行特定的代码
}
以上就是最粗暴的时间比较方法,csdn里面也有其他类似的,但个人感觉,简单易懂才是真的,直接获取年的数字,月的数字,日的数字,然后比较,多简单,额外的也可以拓展到时,分,秒,
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)