From a1c028dfeaae0eeef7776696875c464e97d00c5c Mon Sep 17 00:00:00 2001 From: parkyejin Date: Thu, 5 Sep 2024 00:05:46 +0900 Subject: [PATCH] =?UTF-8?q?feat(#63):=20formatAMPM=20=ED=98=95=EC=8B=9D=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/chatting/page.tsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/app/chatting/page.tsx b/src/app/chatting/page.tsx index 11db24d..b901a7d 100644 --- a/src/app/chatting/page.tsx +++ b/src/app/chatting/page.tsx @@ -22,6 +22,17 @@ const Chatting = () => { const [messages, setMessages] = useState([]) + const formatAMPM = (date: Date) => { + let hours = date.getHours() + let minutes: number | string = date.getMinutes() + const ampm = hours >= 12 ? '오후' : '오전' + hours %= 12 + hours = hours || 12 + minutes = minutes < 10 ? `0${minutes}` : minutes + const formattedTime = `${ampm} ${hours}:${minutes}` + return formattedTime + } + // 1. 메시지 수신 핸들러 함수 const handleWebSocketMessage = (newMessage: ChattingMessageI) => { if (userInfo && userInfo.id !== Number(newMessage.memberId)) { @@ -138,7 +149,7 @@ const Chatting = () => { ...prevMessages, { message: input, - timestamp: new Date().toISOString(), + timestamp: formatAMPM(new Date()), memberId: userInfo?.id?.toString() || '', }, ])