例如:开始时间为 '2003-10-17 21:15:00'
      结束时间为 '2003-10-17 21:30:00'
则开始实践和结束时间之间的差值为 15分钟
我的问题就是如何使用java方法计算得到 这个15分钟(使用sql语句也行)
请给出具体的实现方法,谢谢!!

解决方案 »

  1.   

    String t1="2005-6-8 21:18:44";
    String t2="2005-6-8 21:25:44";
    SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    ParsePosition pos = new ParsePosition(0);
    Date d1 = formatter.parse(t1, pos); 
    pos = new ParsePosition(0);
    Date d2 = formatter.parse(t2, pos);
    long ms=d2.getTime()-d1.getTime();
    System.out.println(ms/60000);
      

  2.   

    请教一下,如何读取系统当前时间的具体时间,具体到秒?
    还有,ParsePosition pos = new ParsePosition(0); 这句话是什么意思,有何用处?
      

  3.   

    //ParsePosition好像是某些格式化之类的方法需要调用时需要做参数的一个对象,应该是记录位置在转换中的位置,参看JDK的描述吧public class ParsePosition
    extends Object
    ParsePosition is a simple class used by Format and its subclasses to keep track of the current position during parsing. The parseObject method in the various Format classes requires a ParsePosition object as an argument. By design, as you parse through a string with different formats, you can use the same ParsePosition, since the index parameter records the current position. 
      

  4.   

    import java.text.SimpleDateFormat;
    import java.text.ParseException;
    import java.util.Date;class testDate{
        public static void main(String[] args) throws Exception
        {
            
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            dateFormat.setLenient(false);
            Date date = dateFormat.parse("2005-05-24 09:00:00");
            Date fdate=new Date();
            //计算差值,你可以把3600000再除以60得到分钟
            long l=(fdate.getTime()-date.getTime())/3600000;
            System.out.println(l);
            
        }    
    }
      

  5.   


    //java中取当前时间用java.util.Date就行了,不过最好进行一下时间格式的转换java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy/MM/dd HH/mm/ss"); 
    java.util.Date date=new java.util.Date();
    System.out.println(formatter.format(date));
    //最后建议楼主,如果要计算精确到秒的化,尽量直接用SQL写,因为如果插入数据是用数据库的系统时间的化,不能保证应用服务器和数据库的系统时间完全一致