-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorkInfo.java
More file actions
57 lines (40 loc) · 1.24 KB
/
Copy pathWorkInfo.java
File metadata and controls
57 lines (40 loc) · 1.24 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.test0220;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class WorkInfo {
private String date;
private String work;
private int days;
public WorkInfo(String date, String work, int days) {
this.date = date;
this.work = work;
this.days = days;
}
public String getDate() {
return date;
}
public String getWork() {
return work;
}
public int getDays() {
return days;
}
public void printInfo() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
Date start = null;
try {
start = sdf.parse(date);
} catch (Exception e) {
System.out.println("잘못된 값이 입력되었습니다.(종료)");
return;
}
Calendar c = Calendar.getInstance();
c.setTime(start); // Date가 캘린더에 저장
c.add(Calendar.DATE, days);
Date end = c.getTime(); // Calendar를 Date로 변환
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy년 MM월 dd일");
System.out.println(work + "의 시작일은 " + sdf2.format(start) + "이고 " + sdf2.format(end) + "까지 수행해야 합니다.");
// 메서드 내에만 사용하는 변수는 메서드 안에서 인스턴스 변수로 선언하자
}
}