java 有沒有得到昨天日期的函數?Help!!!!!!

解决方案 »

  1.   

    先取今天,然后减去1天的时间就得到了。
    如:
    Date d=new Date();
    d=new Date(d.getTimes()-1000*3600-24);//昨天或者用Calendar类。
      

  2.   

    Calendar rightNow = Calendar.getInstance();
    GregorianCalendar gc1 = new GregorianCalendar(rightNow.get(Calendar.YEAR), rightNow.get(Calendar.MONTH),
    rightNow.get(Calendar.DAY_OF_MONTH));
    gc1.add(Calendar.DATE, -1);
    Date d1 = (Date)gc1.getTime();
      

  3.   

    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.DATE, -1);
    String yesterday = new SimpleDateFormat("yyyy-MM-dd").format(cal.getTime());
      

  4.   

    謝謝﹗輸出的月份是Tue Jul 31 09:21:45 CST 2007
    能不能控制格式象月份Jul要把它轉換具體數字7﹐這個怎么做?
      

  5.   

    Date date = new Date();date.setTime(date.getTime()-24*60*60*1000);
      

  6.   

    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    Date dd = df.format(date);