int a() {
        Date start_date = null;
        Date end_date = null;
        try {            DateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm");
            start_date = df.parse("2012-01-11 11:10");
            end_date = df.parse("2012-01-11 12:08");
            Log.v("a", "start" + start_date.getTime());
            Log.v("a", "end  " + end_date.getTime());            
        }
        catch(Exception e) {
            return -1;
        }
        return (int) ((end_date.getTime() - start_date.getTime()) / (1000 * 60));如果时间在中午11点和12点之间就会有问题 他返回的时差不对 其他的时间段暂时未发现问题
当前代码返回值是-662
求解

解决方案 »

  1.   

    DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");这样试试看
      

  2.   


    我还发现另一种方法 
    int a() {
      Date start_date = null;
      Date end_date = null;
      try {
    start_date = Timestamp.valueOf(year.split(" ")[0] + " " + hour+ ":00");
    end_date = Timestamp.valueOf(yearr.split(" ")[0] + " " + hourr+ ":00");
      }
      catch(Exception e) {
      return -1;
      }
      return (int) ((end_date.getTime() - start_date.getTime()) / (1000 * 60));
    ----------------------------
    为什么问个问题都没几个人回答