Skip to content

Commit

Permalink
Merge pull request #82 from MOVIEJOJO7/Feature/#81
Browse files Browse the repository at this point in the history
feat: 메세지 전송 시간 기능 추가
  • Loading branch information
hhjs2 authored Nov 16, 2023
2 parents 0e2a92a + 84f9f9b commit 3a09ab5
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions Components/Chat/Chats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,27 @@ const Chats = ({
router.push(`/profile/${user.id}?isMyProfile=false`);
};

const changeTime = (messageData: string) => {
const createdAt = new Date(messageData);

// 시간 포맷팅
const formattedTime = `${createdAt
.getHours()
.toString()
.padStart(2, '0')}:${createdAt.getMinutes().toString().padStart(2, '0')}`;

return formattedTime;
};

return (
<>
{user.id === myId ? (
<li key={message.id} className="flex m-2 place-self-end text-white">
<li key={message.id} className="flex m-2 place-self-end">
<p className="text-black">
{changeTime(message.createdAt.toString())}
</p>
<div className="flex flex-col ml-2">
<p className="px-5 py-2 text-sm bg-gray-500 rounded-xl">
<p className="px-5 py-2 text-sm bg-gray-500 text-white rounded-xl">
{message.text}
</p>
</div>
Expand All @@ -44,6 +59,7 @@ const Chats = ({
{message.text}
</p>
</div>
<p>{changeTime(message.createdAt.toString())}</p>
</li>
)}
</>
Expand Down

0 comments on commit 3a09ab5

Please sign in to comment.