两个日期时间都取它们的long值,不就可以比较了吗。

解决方案 »

  1.   

    to  zhigangxie(易道模型) ( 
    GregorianCalendar类型 可以存放时间日期,但不能从一个字符串直接转换到该类型,最主要的,我想问一下GregorianCalendar.after方法从文档和源码上看,他似乎只比较GregorianCalendar中的时间部分,而不比较日期?!to  shengming_jing() ( ) 
    要怎么做?哦  忘了 我还想得到两个日期时间之间的差值 以分钟为单位例如 [2004年2月1日1时29分35秒] - [2004年2月1日1时50分35秒] 返回 21分钟麻烦各位给写点代码吧 伪的也行啊 如果能编译通过那是最好了
    谢谢
      

  2.   

    Date date1 = new Date();         Calendar calendar = new GregorianCalendar();
            calendar.setTime(date1);        calendar.add(Calendar.MILLISECOND, 1000);
            Date date2 = calendar.getTime();
            
            boolean after = date1.after(date2);
            System.out.println( "date1: " + date1.toString() );
            System.out.println( "date2: " + date2.toString() );
            System.out.println( "after " + after );
      

  3.   

    毫秒也可以比较,没问题的,以下比较是差一秒运行结果:date1: Fri Oct 22 12:48:14 CST 2004
    date2: Fri Oct 22 12:48:15 CST 2004
    after false
      

  4.   

    to kaleon(初学者) 
    java在这方面不会真这么弱吧 没看上去再好一点的做法???
      

  5.   

    毫秒也可以比较,没问题的,以下比较是差一秒运行结果:date1: Fri Oct 22 12:48:14 CST 2004
    date2: Fri Oct 22 12:48:15 CST 2004
    after false
      

  6.   

    to  icy_csdn() 
    不好意思 我一开始举的例子可能不太恰当
    我是想要
    [2004年2月1日1时29分35秒].after[2004年2月2日1时29分34秒] 返回 false
      

  7.   

    GregorianCalendar.after方法从文档和源码上看,他似乎只比较GregorianCalendar中的时间部分,而不比较日期?!
    也就是说
    [2004年2月1日1时29分35秒].after[2004年2月2日1时29分34秒] 我会得到一个true
    而事实上 我要的是一个false 应为2004年2月1日1在2004年2月2日之前
      

  8.   

    GregorianCalendar cal = new GregorianCalendar();
         cal.set(2004,2 - 1, 1, 1, 29, 35); GregorianCalendar cal2 = new GregorianCalendar();
    cal2.set(2004,2 - 1, 2, 1, 29, 34);
        
         System.out.println(cal.after(cal2));输出就是 false,何来的true???????
      

  9.   

    to  ChDw(米) 
    恩 这个我还没有试过,仅仅是从文档上看 有点怀疑,想证实一下
    jdk doc里的内容如下
    after public boolean after(Object when)Compares the time field records. Equivalent to comparing result of conversion to UTC. Parameters:when - the Calendar to be compared with this Calendar. Returns:true if the current time of this Calendar is after the time of Calendar when; false otherwise那么 我还想得到两个日期时间之间的差值 以分钟为单位例如 [2004年2月1日1时29分35秒] - [2004年2月1日1时50分35秒] 返回 21分钟
    该怎么做????????????????????????
      

  10.   

    long t1 = cal.getTime().getTime();//毫秒1
    long t2 = cal2.getTime().getTime();//毫秒2int minDiff = (t2 - t1) / (1000 * 60);