由system.currentTimeMillis() 获得当前的时间

System类代表系统,系统级的很多属性和控制方法都放置在该类的内部。该类位于java.lang包。

currentTimeMillis方法

public static long currentTimeMillis()

该方法的作用是返回当前的计算机时间,时间的表达格式为当前计算机时间和GMT时间(格林威治时间)1970年1月1号0时0分0秒所差的毫秒数。

可以直接把这个方法强制转换成date类型。

代码如下:

long currentTime = System.currentTimeMillis();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy年-MM月dd日-HH时mm分ss秒");
Date date = new Date(currentTime);
System.out.println(formatter.format(date));

运行结果如下:

当前时间:2011年-08月10日-14时11分46秒

另:

可获得当前的系统和用户属性:

       String osName = System.getProperty(“os.name”);

  String user = System.getProperty(“user.name”);

  System.out.println(“当前操作系统是:” + osName);

  System.out.println(“当前用户是:” + user);

       System.getProperty 这个方法可以得到很多系统的属性。

 

转自:http://blog.csdn.net/mywebstudy/article/details/7814695

 

原文地址:https://www.cnblogs.com/heyonggang/p/3992687.html