Date now=new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
System.out.println(formatter.format(now));

解决方案 »

  1.   

    to tomtian(老猫):这种方法我知道,但是我主要想搞清Calendar
      

  2.   

    //*********************************************
    //功  能:
    //参  数:
    //返回值:
    //*********************************************
    public static String getTime()
    {
    String strTime = "";
    cal = new GregorianCalendar();
    nYear = cal.get(Calendar.YEAR);
    nMonth = cal.get(Calendar.MONTH);
    nDate = cal.get(Calendar.DAY_OF_MONTH);
    nHour = cal.get(Calendar.HOUR);
    nMin = cal.get(Calendar.MINUTE);
    nSec = cal.get(Calendar.SECOND); strTime += nYear;
    if (nMonth < 10)
    {
    strTime += "-0";
    }
    else
    {
    strTime += "-";
    }
    nMonth++;
    strTime += nMonth; if (nDate < 10)
    {
    strTime += "-0";
    }
    else
    {
    strTime += "-";
    }
    strTime += nDate; if (nHour < 10)
    {
    strTime += " 0";
    }
    else
    {
    strTime += " ";
    }
         strTime += nHour; if (nMin < 10)
    {
    strTime += ":0";
    }
    else
    {
    strTime += ":";
    }
    strTime += nMin; if (nSec < 10)
    {
    strTime += ":0";
    }
    else
    {
    strTime += ":";
    }
    strTime += nSec;
    return strTime; }
        private static Calendar cal = null;    private static int nYear    = 0;
        private static int nMonth   = 0;
        private static int nDate    = 0;
        private static int nHour    = 0;
        private static int nMin     = 0;
        private static int nSec     = 0;
      

  3.   

    System.out.println(formatter.format(cal.toTime()));
      

  4.   

    你可以直接看到它的源码,Calendar是个抽象类,YEAR是一个final的变量
    默认的getInstance调用 new GeorageCalendar()
      

  5.   

    System.out.pritnln(Calendar.YEAR+"-"+Calendar.MONTH+"-"+Calendar.DATE);老兄,Calendar.YEAR 只是一个常量 ,它永远都是1 .同样Calendar.MONTH 代表的是2,
    Calendar.DATE代表的是5 .它们是一个常量就像你自己定义一个 int ABCD = 5 一样
    这里的ABCD 就是 Calendar.YEAR .它只是一个名字,不是 Calendar.getYear() !!!!!
      

  6.   

    同意楼上的意见,但有个小小的问题Calendar类有getYear()方法马??
    这样就行了
    Calendar calendar = Calendar.getInstance();
    System.out.print(calendar.get(Calendar.MONTH)+1);