System 类
import java.util.*;
public class DEMO2 {
private static final String FILE_SEPARATOR = System.getProperty("file.separator");
private static final String PATH_SEPARATOR = System.getProperty("path.separator");
private static final String LINE_SEPARATOR = System.getProperty("line.separator");
public static void main(String[] args) {
long time = System.currentTimeMillis();
System.out.println(time);
Properties p = System.getProperties();
Set<String> key = p.stringPropertyNames();
for (String s : key) {
String values = p.getProperty(String.valueOf(s));
System.out.println(s + " : " + values);
}
System.out.println(p.getProperty("os.name"));
System.out.println(System.getProperty("os.name"));
System.out.println("c:" + FILE_SEPARATOR + "abc" + FILE_SEPARATOR + "d.text");
System.out.println("c:" + PATH_SEPARATOR + "d:");
System.out.println("Hallo" + LINE_SEPARATOR + "word");
}
}
Runtime 类
Runtime r=Runtime.getRuntime();
r.exec("\"C:\\Program Files (x86)\\Thunder Network\\Thunder\\Program\\ThunderStart.exe\"-StartType:DesktopIcon");
r.exec("notepad.exe C:\\Users\\jackchan\\Desktop\\gggg.txt");
Math 类
System.out.println(Math.ceil(10.111));
System.out.println(Math.floor(10.111));
System.out.println(Math.round(10.66));
System.out.println(Math.max(99,99.5));
System.out.println(Math.pow(10,3));
for (int i=0;i<20;i++){
int d=(int)(Math.ceil(Math.random()*6));
System.out.println(d);
}
Random r=new Random();
System.out.println(r.nextDouble());
System.out.println(r.nextBoolean());
Date 类
Date date = new Date();
System.out.println(date);
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
df=new SimpleDateFormat("yy/MM/dd E hh:mm:ss");
String str_date = df.format(date);
System.out.println(str_date);
String str="2017-02-25";
DateFormat dff=DateFormat.getDateInstance();
Date d=dff.parse(str);
System.out.println(d);
long time=1581666279260L;
Date d1=new Date(time);
String s=df.format(d1);
System.out.println(s);
long time1=d1.getTime();
System.out.println(time1);
Calendar 类 日历
Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
String week = getWeek(c.get(Calendar.DAY_OF_WEEK));
System.out.println(year + "/" + month + "/" + day + "/" +week);
c.set(2018,7,9);
c.add(Calendar.MONTH,-1);
int year=2014;
c.set(year,2,1);
c.add(Calendar.DAY_OF_MONTH,-1);
private static String getWeek(int i) {
if (i >= 7 || i <= 0) {
throw new NotTheWeekException("无对应日期");
}
String[] s = {"", "星期七", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
return s[i];
}
String s1 = "2012-5-28";
DateFormat df1 = DateFormat.getDateInstance(DateFormat.MEDIUM);
Date d1 = df1.parse(s1);
String s2 = "2012/3/17";
DateFormat df2 = new SimpleDateFormat("yyyy/MM/dd");
Date d2 = df2.parse(s2);
long time1=d1.getTime();
long time2=d2.getTime();
System.out.println(time1);
System.out.println(time2);
long time3=time1-time2;
System.out.println(time3/1000/60/60/24);