|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
// 오늘 날짜
Calendar cal = Calendar.getInstance();
String format = "yyyy-MM-dd";
SimpleDateFormat sdf = new SimpleDateFormat(format);
String date = sdf.format(cal.getTime());
System.out.println(date);
// 어제 날짜
Calendar cal = Calendar.getInstance();
String format = "yyyy-MM-dd";
SimpleDateFormat sdf = new SimpleDateFormat(format);
String date = sdf.format(cal.getTime());
System.out.println(date);
|
|
1
2
3
4
5
6
|
Calendar cal = Calendar.getInstance();
String format = "yyyy-MM-dd";
SimpleDateFormat sdf = new SimpleDateFormat(format);
String date = sdf.format(cal.getTime());
System.out.println(date);
|
cs |
https://myhappyman.tistory.com/45
Java - 오늘, 어제, 이번달, 올해, 지난해 등 날짜 구하기
Java 1.8버전 이하에서는 날짜를 구하려면 Calendar 객체를 호출하고 데이트포맷을 설정하여 문자열로 받아와 출력을 해줘야 한다. Java에서 날짜를 구하는 함수를 만들어서 공유하고자 포스팅한다. 오늘 날짜 구..
myhappyman.tistory.com
'Java' 카테고리의 다른 글
| [JAVA] W/System.err: java.lang.NumberFormatException: For input string: (0) | 2020.01.21 |
|---|---|
| [Java] try-with-resources 예외처리 (0) | 2019.10.01 |