System.currentTimeMillis(),獲取系統當前時間
阿新 • • 發佈:2019-01-08
System.currentTimeMillis(),該方法的作用是返回當前的計算機時間,時間的表達格式為當前計算機時間和GMT時間(格林威治時間)1970年1月1號0時0分0秒所差的毫秒數。
/**獲取系統當前時間*/ public String getNowDate(){ long currentTime = System.currentTimeMillis(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日HH時mm分"); Date date = new Date(currentTime); String nowDate = formatter.format(date); return nowDate; }
可獲得當前的系統和使用者屬性:
String osName = System.getProperty(“os.name”);
String user = System.getProperty(“user.name”);
System.out.println(“當前作業系統是:” + osName);
System.out.println(“當前使用者是:” + user);
System.getProperty 這個方法可以得到很多系統的屬性。
說明文件地址(中文):http://tool.oschina.net/apidocs/apidoc?api=jdk-zh