Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- 티스토리챌린지
- Firebase
- ChatGPT
- 오블완
- Eclipse
- java
- vscode
- github
- 스파르타코딩클럽
- spring
- 웹개발
- jQuery
- error
- 자바
- bootstrap
- 코딩
- 이클립스
- SQL
- Spring Security
- CSS
- myBatis
- 깃허브
- 배포
- HTML
- restapi
- SQLD
- jsp
- 기업설명회
- JavaScript
- AJAX
Archives
- Today
- Total
푸들푸들
날짜 포맷(Format) 본문
DB에서 NOW()가 기본 값인 create_date를 jsp에서 출력하면
2023-05-27T22:51:19 이런 형식으로 나온다
이것을 2023/05/27 22:51 형식으로 바꾸려고 함
1. 자바스크립트
<p style="text-align: right;">
작성시간: <span id="formattedCreateDate">${b.createDate}</span>
<c:if test="${not empty b.updateDate}">
| 수정시간: <span id="formattedUpdateDate">${b.updateDate}</span>
</c:if>
</p>
<script>
/* 날짜 포맷 */
const createDateString = "${b.createDate}";
const updateDateString = "${b.updateDate}";
// Date 객체로 변환
const bCreateDate = new Date(createDateString);
const bUpdateDate = new Date(updateDateString);
// 날짜 형식 변환 함수 (yyyy-MM-dd HH:mm)
function formatDate(dateString) {
const date = new Date(dateString);
return date.toLocaleString('ko-KR', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
hour12: false
}).replace(',', ''); // "," 제거
}
// 변환된 날짜를 화면에 출력
document.getElementById('formattedCreateDate').textContent = formatDate(bCreateDate);
document.getElementById('formattedUpdateDate').textContent = formatDate(bUpdateDate);
</script>
->
2. 쿼리(맵퍼, SQL)
: DATE_FORMAT(b.create_date,'%y년%c월%e일 %H:%i')
SELECT
b.boa_no boaNo
, e.ename ename
, b.title
, DATE_FORMAT(b.create_date,'%Y/%c/%e %H:%i') createDate
, b.view_cnt viewCnt
, b.cat_no catNo
, COUNT(bc.com_no) countComment
FROM board b
INNER JOIN emp e
ON b.emp_no = e.emp_no
LEFT JOIN board_comment bc
ON b.boa_no = bc.boa_no
WHERE b.cat_no = 1
GROUP BY b.boa_no
ORDER BY b.boa_no DESC
->
'구디아카데미 > Project' 카테고리의 다른 글
AWS LightSail에서 war 파일 배포 (1) | 2025.02.10 |
---|---|
<textarea> 내용의 줄바꿈 적용하여 불러오기 (0) | 2025.01.31 |
소스트리(Source tree) 충돌 해결 - 스태시(Stash) (0) | 2025.01.20 |
1125 [Mall] (0) | 2024.11.25 |
[Mall] 웹 설계서 작성 (0) | 2024.11.24 |