System.out.println(
  new java.text.SimpleDateFormat("yyyy-MM-dd").format(
     new java.util.Date()));

解决方案 »

  1.   

    Date date=new Date(System.currentMillinous);
      

  2.   

    //:c:\j2skd1.4.1\javastudy\class\HelloDate.java
    import java.util.Date;
    /** The first Thinking in Java example program.
    * Displays a string and today's date.
    * @author Bruce Eckel
    * @author www.BruceEckel.com
    * @version 2.0
    */
    public class HelloDate{
    /** Sole entry.point to class & application
     *  @param asg array of string arguments
     *  @return NO return value
     *  @exception exception No exception thrown
    */
      HelloDate(){
      
       }
      public static void main(String asg[]){
        System.out.println("Hello,it's: ");
        System.out.println(new Date());
      
       }
    }///:-
      

  3.   

    public void TimeTest()
        {
            String lastdate="";
          /*
           Symbol   Meaning                 Presentation        Example
     ------   -------                 ------------        -------
     G        era designator          (Text)              AD
     y        year                    (Number)            1996
     M        month in year           (Text & Number)     July & 07
     d        day in month            (Number)            10
     h        hour in am/pm (1~12)    (Number)            12
     H        hour in day (0~23)      (Number)            0
     m        minute in hour          (Number)            30
     s        second in minute        (Number)            55
     S        millisecond             (Number)            978
     E        day in week             (Text)              Tuesday
     D        day in year             (Number)            189
     F        day of week in month    (Number)            2 (2nd Wed in July)
     w        week in year            (Number)            27
     W        week in month           (Number)            2
     a        am/pm er            (Text)              PM
     k        hour in day (1~24)      (Number)            24
     K        hour in am/pm (0~11)    (Number)            0
     z        time zone               (Text)              Pacific Standard Time
     '        escape for text         (Delimiter)
     ''       single quote            (Literal)           '
     Examples Using the US Locale: Format Pattern                         Result
     --------------                         -------
     "yyyy.MM.dd G 'at' hh:mm:ss z"    ->>  1996.07.10 AD at 15:08:56 PDT
     "EEE, MMM d, ''yy"                ->>  Wed, July 10, '96
     "h:mm a"                          ->>  12:08 PM
     "hh 'o''clock' a, zzzz"           ->>  12 o'clock PM, Pacific Daylight Time
     "K:mm a, z"                       ->>  0:00 PM, PST
     "yyyyy.MMMMM.dd GGG hh:mm aaa"    ->>  1996.July.10 AD 12:08 PMCode Sample: SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, "PST");
     pdt.setStartRule(DateFields.APRIL, 1, DateFields.SUNDAY, 2*60*60*1000);
     pdt.setEndRule(DateFields.OCTOBER, -1, DateFields.SUNDAY, 2*60*60*1000);
            // Format the current time.
     SimpleDateFormat formatter
         = new SimpleDateFormat ("yyyy.mm.dd e 'at' hh:mm:ss a zzz");
     Date currentTime_1 = new Date();
     String dateString = formatter.format(currentTime_1);
            // Parse the previous string back into a Date.
     ParsePosition pos = new ParsePosition(0);
     Date currentTime_2 = formatter.parse(dateString, pos);
          */
            //mmm代表月份--大写M代表用汉字表示,小写代表用数字表示,3个m代表月份用3位数来表示.
            SimpleDateFormat  formatter = new SimpleDateFormat("EEE mm dd hh:mm:ss yyyy", Locale.getDefault());
            Date currentDate = new Date();
            lastdate = formatter.format(currentDate);
            System.out.println("SimpleDateFormat:"+lastdate);
            SimpleDateFormat m_oFormatTimeOnly=new SimpleDateFormat("hh:mm:ss", Locale.getDefault());
            String   m_strOnlyTime = m_oFormatTimeOnly.format(currentDate);
            System.out.println("OnlyTime:"+m_strOnlyTime);        SimpleDateFormat m_oFormatOnlyYear=new SimpleDateFormat("yyyy", Locale.getDefault());
            String   m_strOnlyYear = m_oFormatOnlyYear.format(currentDate);
            System.out.println("OnlyYear:"+m_strOnlyYear);        SimpleDateFormat m_oFormatYMD=new SimpleDateFormat("yyyy.MM.dd", Locale.getDefault());
            String   m_strOnlyYMD = m_oFormatYMD.format(currentDate);
            System.out.println("OnlyYear:"+m_strOnlyYMD);
        }
      

  4.   

    你要得到的是当前的时间吗? System.currentTimeMillis()