数据库中保存的是varchar型的  30/Dec/2007:04:47:33 +0800  这种时间,如何取出并计算两个相临的时间差看是否大于30分钟

解决方案 »

  1.   


    public boolean getQuot(String time1) {
    boolean bool = false;
        long quot = 0;
        SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date date1 = ft.parse(time1);
            Date date2 = new Date();
            if(date1.getTime()<date2.getTime()){
            quot =  date2.getTime()- date1.getTime();
            quot = quot / 1000 / 60 / 60 / 24;
            if(quot>0){
             bool = false;
            }else{
             bool = true;
            }
            }else{
             bool = false;
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return bool;
    }
      

  2.   

    请参考
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.Locale;public class Test {
      private static final SimpleDateFormat format = new SimpleDateFormat("dd/MMM/yyyy HH:mm:ss Z", Locale.US);  public static Date getDate(String str) throws ParseException {
        return format.parse(str);
      }  public static void main(String[] args) throws ParseException {
        String str1 = "30/Dec/2007 04:47:33 +0800";
        String str2 = "30/Dec/2007 05:17:33 +0800";
        long d1 = getDate(str1).getTime();
        long d2 = getDate(str2).getTime();
        System.out.println((d2 - d1) > 30 * 60 * 1000);
      }
    }