1.获取时间
long begin=System.currentTimeMillis();//单位毫秒
long end=System.nanoTime();//单位纳秒
Date d = new Date();
long longtime = d.getTime();
System.out.println(longtime);
String time = d.toLocaleString();
System.out.println(time);//标准格式时间
2.String和int互转
(1)int to string
int ->String
int i= 10;
String s = ""+10;//利用java中的‘+’连接符。
//或者利用Integer的toString方法。String s = new Integer(i).toString();
(2) string to int
String ->int
String s = "123";
int i = Integer.parseInt(s);//利用java中int基本类型的封装类Integer的parseInt方法。
3.java 模仿c宏定义
写一个接口,定义数据类型static final,然后用类实现。
4.写入文件
try {
//打开一个写文件器,构造函数中的第二个参数true表示以追加形式写文件
FileWriter writer = new FileWriter(fileName, true);
writer.write(content);
writer.close();
} catch (IOException e) {
e.printStackTrace();