package test;
import java.util.Date;
import java.util.Scanner;
import java.text.DateFormat;
import java.text.SimpleDateFormat;import static testd.console.output;
public class test { /**
 * @param args
 */
public static String GetDate(String strFoemat)
    {
        SimpleDateFormat sdf = new SimpleDateFormat(strFoemat);
      Date date=new Date();
      return sdf.format(date);
    }
public static void main(String[] args) {
long starttime=new Date().getTime();
     System.out.println(starttime);
     Scanner scanner=new Scanner(System.in);
     String ch=scanner.next();
     long endtime=new Date().getTime();
     long minus=endtime-starttime;
     output("现在时间是:%1$tT%n",System.currentTimeMillis());
    DateFormat df=DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL);
     output(df.format(new Date()));
     String a=GetDate("yyyy年MM月dd日");
     System.out.println(a);
    
     // TODO Auto-generated method stub
     
    
}
}
package testd;import java.io.PrintStream;public class console {
private static PrintStream out=System.out;
public static void output(String format,Object... msgs)

out.printf(format,msgs);
   

    }
    }
这是我仿照写的显示时间日期函数  谁能告诉我Object... 用法以及    output("现在时间是:%1$tT%n",System.currentTimeMillis());这种格式的用法

解决方案 »

  1.   

    可变参数,Java 1.5的新特性。使得output方法的参数在format以后可以有任意多个,在方法内部,msgs相当于一个Object数组。
    console这个类整个没什么意义,只是简单地把System.out.printf()包装了一下,printf()即格式化输出,也是1.5新特性。具体用法可以查看javadoc。
      

  2.   

    你可以理解为 Object[] 
    class Test {
      public static int max(int... numbers) {
        int max = Integer.MIN_VALUE;
        for (int number : numbers) {
          if (number > max) {
            max = number;
          }
        }
        return max;
      }  public static void main(String[] args) {
        System.out.println(max(1, 3, 5, 6, 8, 10));
      }
    }
    最可能的一个应用,输入不定数量的整数,拿到最大值,其实理解成
    max(int[] numbers) 一样的。