Android 两次相加

Android 两次相加,android,time,Android,Time,所以我想比较一下时间,在做了一个快速的谷歌搜索并阅读了API之后,我还没有找到任何解决方案。 这就是我的情况。 假设我有时间t,并且该时间设置为特定时间。我想在这个时间上再加2分钟,所以t=+2分钟。然后Time current将被设置为当前时间,我想使用时间。比较(时间,时间),检查t是否大于或小于当前时间。这是目前为止唯一的伪代码,我不知道如何向时间变量添加2分钟。如果有任何其他可行的选项,也建议它们:)使用库,这将解决简单api的问题。了解此内容以进行日期比较 Date date =

所以我想比较一下时间,在做了一个快速的谷歌搜索并阅读了API之后,我还没有找到任何解决方案。 这就是我的情况。

假设我有
时间t
,并且该时间设置为特定时间。我想在这个时间上再加2分钟,所以
t=+2分钟
。然后
Time current
将被设置为当前时间,我想使用
时间。比较(时间,时间)
,检查
t
是否大于或小于
当前时间。这是目前为止唯一的伪代码,我不知道如何向时间变量添加2分钟。如果有任何其他可行的选项,也建议它们:)

使用库,这将解决简单api的问题。

了解此内容以进行日期比较

  Date date = new Date(98, 5, 21);
  Date date2 = new Date(99, 1, 9);

  // make 3 comparisons with them
  int comparison = date.compareTo(date2);
  int comparison2 = date2.compareTo(date);
  int comparison3 = date.compareTo(date);

  // print the results
  System.out.println("Comparison Result:" + comparison);
  System.out.println("Comparison2 Result:" + comparison2);
  System.out.println("Comparison3 Result:" + comparison3);
比较结果:-1

比较2结果:1

比较3结果:0

添加分钟数

Date jamBanding = new Date();
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(jamBanding.getTime());

cal.add(cal.MINUTE, 2)

jamBanding = cal.getTime(); //here is the date now + 2 minute
试试这个

String myTime = "02:50";
SimpleDateFormat df = new SimpleDateFormat("HH:mm");
Date d = null;
try {
    d = df.parse(myTime);
    } catch (ParseException e) {
    }
Calendar cal = Calendar.getInstance();
cal.setTime(d);
cal.add(Calendar.MINUTE,10);
String newTime = df.format(cal.getTime());
System.out.println("New Time : " + newTime);

试试这个方法

public boolean isTimeGreaterThenCurrent(Time t) {
        long timeGiven = ((t.hour*60)*60) + (t.minute*60) + (t.second);
        long timeCurrent=0;
        Calendar c = Calendar.getInstance();
        timeCurrent = ((c.get(Calendar.HOUR_OF_DAY)*60)*60) + (c.get(Calendar.MINUTE)*60) + (c.get(Calendar.SECOND));

        if(timeGiven>timeCurrent){
            return true;
        }else{
            return false;
        }

    }

你能试试乔达吗??也许,那会解决你的问题吗?对不起,我没听说过,有链接吗?谢谢,我会查出来的,因为这是最全面的答案:)