문자열을 날짜로 (String to Date)
1. String to Date
String dateString = "2022-10-23 23:14:10";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date parsedDate = sdf.parse(dateString);
2. String to LocalDateTime
String dateSting = "2022-10-23 23:14:10";
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime parsedLocalDateTime = LocalDateTime.parse(dateSting, dtf);
날짜를 문자열로 (Date to String)
1. Date to String
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = sdf.format(date);
2. LocalDateTime to String
LocalDateTime now = new LocalDateTime.now();
String parsedLocalDateTime = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
728x90
'Programing Language > Java' 카테고리의 다른 글
[Java] URL 인코딩 디코딩 ( URLEncoder, URLDecoder ) (0) | 2023.05.24 |
---|---|
[Java] Response File Headers (0) | 2023.03.27 |
[Java] class file has wrong version 61.0, should be 52.0 (0) | 2023.01.30 |
[Java] 명명규칙 (0) | 2023.01.27 |
[Java] API 문서 목록 (0) | 2022.11.01 |
댓글