Java
RSS에서 pubDate 날짜 데이터 포맷팅
jayden-lee
2019. 7. 31. 18:45
728x90
RSS에서 사용하는 pubDate 타입은 다음과 같이 생겼습니다. 아래 이미지는 배달의민족 블로그 피드에서 가져온 내용입니다.
Jsoup 라이브러리를 이용해서 pubDate 값을 가져와서 SimpleDateFormat 클래스를 사용해서 원하는 포맷으로 변경합니다.
String pubDate = "Thu, 18 Jul 2019 18:00:00 +0900";
SimpleDateFormat parseDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.ENGLISH);
SimpleDateFormat formatDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date parseDate = parseDateFormat.parse(pubDate);
String formatDateText = formatDateFormat.format(parseDate);
System.out.println(formatDateText); // 2019-07-18 18:00:00 출력