티스토리 뷰
// 자바 1.8 이상 버전일 경우만 해당 됩니다.
// LocalDate 사용.
// 입력이 문자열일 경우
String s="2024-03-01";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
LocalDate date=LocalDate.parse(s.formatter);
LocalDate lastMonth = date.minusMonths(1);
System.out.println(date);
System.out.println(lastMonth);
// 기준이 오늘 날짜일 경우
LocalDate now=LocalDate.now();
LocalDate lastMonth2=now.minusMonths(1);
System.out.println(date);
System.out.println(lastMonth2);
//결과
date=2024-03-01
lastMonth=2024-02-01
date=2024-03-01
lastMonth2=2024-02-18
//년월말 쓰고 싶을 경우
String yyyyMM=lastMonth2.toString().substring(0,7);
'자바(Java)' 카테고리의 다른 글
Could not read resultset: unexpected end of stream (0) | 2024.05.23 |
---|---|
자바메일 smtp 제목 한글깨짐 (0) | 2024.04.26 |
SQLExeption: Invalid utf8 character string: 'ACED00' (0) | 2024.02.29 |
Truncated class file (0) | 2024.02.28 |
nested exception is java.net.bindexception 주소가 이미 사용중입니다 (0) | 2024.02.21 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- MySQL
- php
- XE
- 파이썬
- 파싱
- 프로씨
- 라이믹스 모듈
- ocjap
- 인포믹스
- esql
- xe addon
- KG
- proc
- xe애드온
- C
- C언어
- EC
- ocajp
- Python
- 포인터
- 스크래핑
- 자바 smtp
- XE3
- 플러터
- JDBC
- webix
- 오라클
- 자바
- 문자열
- 이클립스
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함