반응형
Java에서 사용하는 날짜/시간 타입인 LocalDateTime 과 Date 타입의 다양한 표현방식 예제입니다.
예제코드
출력값
LocalDateTime(Java8 이상) 의 format pattern 예제
dateTime.format(DateTimeFormatter.ofPattern("yyyy-M-dd");
2023-5-23
dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd");
2023-05-23
dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
2023-05-23 21:01:55
dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
2023-05-23 21:01:55
dateTime.format(DateTimeFormatter.ofPattern("yyyyMMdd HH:mm:ss.SSS");
20230523 21:01:55.790
dateTime.format(DateTimeFormatter.ofPattern("yyyy년 MM월 dd일 HH시 mm분 ss초");
2023년 05월 23일 21시 01분 55초
dateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mm:ss");
2023-05-23 09:01:55
dateTime.format(DateTimeFormatter.ISO_TIME);
21:01:55.790389
dateTime.format(DateTimeFormatter.BASIC_ISO_DATE);
20230523
dateTime.format(DateTimeFormatter.ISO_LOCAL_DATE);
2023-05-23
dateTime.format(DateTimeFormatter.ISO_LOCAL_TIME);
21:01:55.790389
dateTime.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
2023-05-23T21:01:55.790389
DateTime 의 format pattern 예제
new SimpleDateFormat("yyyy-M-dd").format(date);
2023-5-23
new SimpleDateFormat("yyyy-MM-dd").format(date);
2023-05-23
new SimpleDateFormat("yyyyMMdd").format(date);
20230523
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
2023-05-23 21:17:19
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").format(date);
2023-05-23 21:17:19.976
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS a").format(date);
2023-05-23 21:17:19.976 오후
new SimpleDateFormat("yyyy년 MM월 dd일").format(date);
2023년 05월 23일
new SimpleDateFormat("yyyy년 MM월 dd일 HH시 mm분 ss초").format(date);
2023년 05월 23일 21시 17분 19초
new SimpleDateFormat("오늘은 yy년 w주차, d번째 날 입니다.").format(date);
오늘은 23년 21주차, 23번째 날 입니다.
new SimpleDateFormat("오늘은 M월 F번째 E요일 입니다.").format(date);
오늘은 5월 4번째 화요일 입니다.
이 포스팅이 도움이 되셨길 바랍니다.
반응형
'언어' 카테고리의 다른 글
[Python] 동시처리/병렬처리 방법 (0) | 2022.03.02 |
---|