“获取当前系统时间”
不需要传递任何东西。
代码如下:
  public java.util.Date getCurrentDate()
  {
      return new java.util.Date(System.currentTimeMillis());
  }

解决方案 »

  1.   

    要首先取道Date类型的数据才能做format。
    像你的要求传进去的format可能是各种各样的,如果返回值是String的话倒还差不多,
    但如果返回Date,format就没有用了。
      

  2.   

    需要的就是返回Date,按照需要的格式
      

  3.   

    那要看你所需要的格式符不符合Date里面的格式了,符合的话,不传参数进去也能取到相应的格式,不符合的话,怎么样也返回不了你制定格式的Date。除非你自己写一个类。
      

  4.   

    import java.text.SimpleDateFormat;
     SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd");
            Date currentTime_1 = new Date();
            String dateString = formatter.format(currentTime_1);
      

  5.   

    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 PM
      Code 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 G '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);
      

  6.   

    用这个试试看:
    import java.text.*;  public Date getCurrentDate(String formatter){
         
         String myString = DateFormat.getDateInstance().format(formatter);   
          
         return java.sql.Date.valueOf(myString );
        
     }
      

  7.   

    指定了格式,只能输出的是String 阿。
    不能是Date拉。还是给你个输出String的吧?
         public static String getCurrentDate(String pattern) {        Date date = new Date();
            SimpleDateFormat df = (SimpleDateFormat)DateFormat.getDateInstance();        synchronized(df) {            df.applyPattern(pattern);            String strDate = df.format(date);            return strDate != null ? strDate : "";
            }
        }        System.out.println(getCurrentDate("MM/dd/yyyy"));
            System.out.println(getCurrentDate("yyyy/MM/dd"));
            System.out.println(getCurrentDate("yyyy.MM.dd G 'at' HH:mm:ss z"));
            System.out.println(getCurrentDate("EEE, MMM d, ''yy" ));
            System.out.println(getCurrentDate("EEE, d MMM yyyy HH:mm:ss Z"));
    输出
    08/13/2003
    2003/08/13
    2003.08.13 西暦 at 16:38:21 GMT+08:00
    水, 8 13, '03
    水, 13 8 2003 16:38:21 +0800
      

  8.   

    上面同样要import java.text.*;我用的日文系统, 你可能看到的就是中文了。