Skip to content

Commit 6d17a24

Browse files
author
shy-coder
committed
day13
1 parent c2e38a5 commit 6d17a24

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.shy.day13;
2+
3+
import java.util.Calendar;
4+
import java.util.Date;
5+
6+
/**
7+
* @ClassName TestCalendar
8+
* @Author shy
9+
* @Date 2020/11/1
10+
**/
11+
public class TestCalendar {
12+
public static void main(String[] args) {
13+
//创建Calendar对象
14+
Calendar cal = Calendar.getInstance();
15+
int year = cal.get(Calendar.YEAR);
16+
int month = cal.get(Calendar.MONTH) + 1;
17+
int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH);
18+
System.out.println(year + "年" + month + "月" + dayOfMonth + "日");
19+
20+
Calendar cal1 = Calendar.getInstance();
21+
cal1.set(Calendar.YEAR,2020);
22+
System.out.println(year + "年" + month + "月" + dayOfMonth + "日");
23+
24+
Calendar cal2 = Calendar.getInstance();
25+
System.out.println(year + "年" + month + "月" + dayOfMonth + "日");
26+
//加2天
27+
cal2.add(Calendar.DAY_OF_MONTH,2);
28+
//减3年
29+
cal2.add(Calendar.YEAR,-3);
30+
System.out.println(year + "年" + month + "月" + dayOfMonth + "日");
31+
32+
Calendar cal3 = Calendar.getInstance();
33+
Date date = cal3.getTime();
34+
System.out.println(date);
35+
}
36+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.shy.day13;
2+
3+
/**
4+
* @ClassName TestSystem
5+
* @Author shy
6+
* @Date 2020/11/1
7+
**/
8+
public class TestSystem {
9+
private static final int MAX = 1000;
10+
11+
public static void main(String[] args) {
12+
//获取当前时间毫秒值
13+
System.out.println(System.currentTimeMillis());
14+
//验证for循环打印数字1-9999所需要使用的时间(毫秒)
15+
long start = System.currentTimeMillis();
16+
for (int i = 0; i < MAX; i++) {
17+
System.out.println(i);
18+
}
19+
long end = System.currentTimeMillis();
20+
System.out.println("共耗时毫秒:" + (end - start));
21+
}
22+
}

0 commit comments

Comments
 (0)