System代表系统,系统级的许多属性和控制方法都放置在这一类中。这一类位于java.lang包。
currentimemilil
public static long currentTimeMillis()
该方法的功能是返回当前的计算机时间。时间表达格式为当前计算机时间与GMT时间(格林威治时间)1970年1月1日0时0分0秒之间的毫秒差。
这种方法可以直接转换为date类型。
代码如下:long currentTime = System.currentTimeMillis();SimpleDateFormat formatter = new SimpleDateFormat(yyyyyy-MM月dd日-HH时m分s秒);Date date = new Date(currentTime);System.out.println(formatter.format(date));
运行结果如下:
2011-08月10日-14:11
另:
可获得当前的系统和用户属性: String osName = System.getProperty(“os.name”);String user = System.getProperty(“user.name”);System.out.println(“当前的操作系统是:” + osName);System.out.println(“当前用户是:” + user);System.getProperty 这种方法可以获得许多系统属性。
