比较如果两个日期在Android的同一周内 [英] Compare if two dates are within same week in android

查看:135
本文介绍了比较如果两个日期在Android的同一周内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 日历c = Calendar.getInstance( ); 
year = c.get(c.YEAR);
month = c.get(c.MONTH);
month ++;
date = c.get(c.DATE);

其他日期分为date2,month2



现在我想看看他们是否在同一周。



可能通过大量的计算和逻辑。发生在第一个日期是3月03日,第二个日期是28Feb。他们都在同一个星期,但很难比较/检查。所以我想知道是否有任何内置的功能或任何方式来比较它们。请帮助..........

解决方案

使用这样的东西:

 日历c = Calendar.getInstance(); 
year1 = c.get(c.YEAR);
week1 = c.get(c.WEEK_OF_YEAR);

日历c = Calendar.getInstance();
c.setTimeInMillis(/ *第二个日期以毫秒为单位* /)
year2 = c.get(c.YEAR);
week2 = c.get(c.WEEK_OF_YEAR);

if(year1 == year2){
if(week1 == week2} {
//做你想要的

}
}
}

这样做:D


I have two dates.Got them from something like......

Calendar c=Calendar.getInstance();
year=c.get(c.YEAR);
month=c.get(c.MONTH);
month++;
date=c.get(c.DATE);

and other date is broken into date2,month2

Now I want to see if both of them are in the same week.

It's possible through lots of calculation and logic.Problem occurs when 1st date is suppose 03 March and 2nd date is 28Feb. Both of them are in same week but difficult to compare/check that. So I want to know if there is any built in function or any way to compare them easily.Please help..........

解决方案

use something like this:

Calendar c=Calendar.getInstance();
year1=c.get(c.YEAR);
week1=c.get(c.WEEK_OF_YEAR);

Calendar c=Calendar.getInstance();
c.setTimeInMillis(/*Second date in millis here*/)
year2=c.get(c.YEAR);
week2=c.get(c.WEEK_OF_YEAR);

if(year1 == year2){
       if(week1 == week2}{
         //Do what you want here

       }
    }
}

This should do it :D

这篇关于比较如果两个日期在Android的同一周内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆