SimpleDateFormat类和System类

SimpleDateFormat

SimpleDateFormat是一个以与语言环境有关的方式来格式化和解析日期的具体类

进行格式化(日期->文本)、解析(文本->日期)

常用的时间模式字母

字母 日期或时间 示例
y 2020
M 年中月份 05
d 年中天数 11
H 1天中小时数(0~23) 15
m 分钟 37
s 49
S 毫秒 748

 

 

 

 

 

 

 

 

 

 

 

 

eg : 

public class Demo03 {
public static void main(String[] args) throws ParseException {
//创建SimpleDateFormat对象y 年 M月
//SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日HH:mm:ss");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
//2.创建Date
Date date = new Date();
//格式化date(把日期转成字符串)
String str = sdf.format(date);
System.out.println(str);
//解析(把字符串转成日期)
Date date2 = sdf.parse("1990/05/01");
System.out.println(date2);
}
}

System类

system系统类,主要用于获取系统的属性数据和其他操作,构造方法私有的

方法名 说明
static void arraycopy(...) 复制数组
static long currentTimeMillis(); 获取当前系统时间,返回的是毫秒值
static void gc(); 建议JVM赶快启动垃圾回收器回收垃圾
static void exit(int status); 退出jvm,如果参数是0表示正常退出jvm,非0表示异常退出jvm

 

 

 

 

 

 

 

 

 

 

 

eg : 

public class Demo04 {
public static void main(String[] args) {
//1.arraycopy:数组的复制
//src:源数组
//srcPos:从哪个位置开始复制0
//destPOS:目标数组的位置
//length:复制的长度
int[] arr = {20,18,15,8,35,26,45,90};
int[] dest = new int[8];
System.arraycopy(arr,4,dest,4,4);
for (int i = 0; i < dest.length; i++) {
System.out.println(dest[i]);
}
//Arrays.copyOf (4,8 ,4);
System.out.println (System.currentTimeMillis());
long start = System.currentTimeMillis();
for (int i = -9999999; i < 99999999; i++) {
for (int j = -9999999; j < 9999999; j++) {
int resilt = i+j;
}
}
//2.获取长短数
long end = System.currentTimeMillis();
System.out.println("用时:"+(end-start));

//3.回收垃圾System.gc();告诉垃圾回收期回收
new Student ("aaa",19);
new Student ("bbb",19);
new Student ("ccc",19);
System.gc();
//4.退出jvm
System.exit(0);
System.out.println("程序结束了...");

}
}
posted @ 2021-03-07 20:46  星忄守候  阅读(45)  评论(0)    收藏  举报