本人是初学者,想请教一下有关java中处理时间的方法比如两个时间分别是
12点24分33秒14点05分45秒如何计算这两个时间点之间隔了多少分钟呢?谢谢各位大虾指点

解决方案 »

  1.   

    用Calendar类,一看API文档便知道该怎么做了。
      

  2.   

    long TIME = 1000L * 60;
    Calendar c1 = new GregorianCalendar(2007, 06, 13, 12, 24, 33);
    Calendar c2 = new GregorianCalendar(2007, 06, 13, 14, 05, 45);
    System.out.printf("%1$tF %<tT%n", c1);
    System.out.printf("%1$tF %<tT%n", c2);
    long n1 = (c1.getTimeInMillis() / TIME)* TIME;  // 将秒重置为0
    long n2 = (c2.getTimeInMillis() / TIME)* TIME;
    System.out.println((n2 - n1) / TIME);
      

  3.   

    呵呵,改一下:long TIME = 1000L * 60;
    Calendar c1 = new GregorianCalendar(2007, 06, 13, 12, 24, 33);
    Calendar c2 = new GregorianCalendar(2007, 06, 13, 14, 05, 45);
    System.out.printf("%1$tF %<tT%n", c1);
    System.out.printf("%1$tF %<tT%n", c2);
    long n1 = c1.getTimeInMillis() / TIME;
    long n2 = c2.getTimeInMillis() / TIME;
    System.out.println( n2 - n1 );
      

  4.   

    在别的地方找到答案了,还是要谢谢一下上面回答我问题的朋友
    下面把我找到的方法贴出来,如果哪位高手有更好的方法也可以贴过来大家共享一下long quot = 0; 
    SimpleDateFormat ft = new SimpleDateFormat("yyyy/MM/dd hh:mm:ss"); 
    try { 
    Date date1 = ft.parse( "2007/7/13 15:56:34" ); 
    Date date2 = ft.parse( "2007/7/13 15:58:45" ); 
    quot = date2.getTime() - date1.getTime(); 
    quot = quot / 1000 / 60 ; 
    } catch (ParseException e) { 
    e.printStackTrace(); 

    System.out.println("时间差"+quot+"分");上面有提到Calendar类的朋友能稍微讲详细一点吗,我看了下他的帮助文档,但没找到相关资料,也可能是我找漏了,内容好多
      

  5.   

    谢谢bao110908(bao)(bao)(讨厌蟑螂) 同学的回答,可是下面这两句我看不明白System.out.printf("%1$tF %<tT%n", c1);
    System.out.printf("%1$tF %<tT%n", c2);
      

  6.   

    第一次来这个论坛,我应该怎样把分给bao110908(bao)(bao)(讨厌蟑螂)同学啊?