-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalendarTest.java
More file actions
42 lines (32 loc) · 1.02 KB
/
CalendarTest.java
File metadata and controls
42 lines (32 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package Date;
import org.junit.Test;
import java.util.Calendar;
import java.util.Date;
public class CalendarTest {
@Test
public void testCalendar(){
//实例化
Calendar calendar = Calendar.getInstance();
System.out.println(calendar.getClass());
//常用方法
//get()
int days = calendar.get(Calendar.DAY_OF_MONTH);
System.out.println(days);
//set()
calendar.set(Calendar.DAY_OF_MONTH,24);
days = calendar.get(Calendar.DAY_OF_MONTH);
System.out.println(days);
//add()
calendar.add(Calendar.DAY_OF_MONTH,-4);
days = calendar.get(Calendar.DAY_OF_MONTH);
System.out.println(days);
//getTime():日历类转换为Date
Date date = calendar.getTime();
System.out.println(date);
//setTime():Date转换为日历类
Date date1 = new Date();
calendar.setTime(date1);
days = calendar.get(Calendar.DAY_OF_MONTH);
System.out.println(days);
}
}