Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
how to manage text message time stamp for chat app

I'm actually building a chat app and using react and when I send a message it takes my local time and saved it to the database and using socket io library the receiver will get the message the problem is first it will work fine if both sender and receiver have the same timezone but if they have different timezones it will say just now for the sender but for the receiver 5 hours ago how to fix that is there any library or is a way to fix the code

and also I'm using timeago.js to format the timestamp like, just now,4 hours ago...

//sender side

const socketMessage = {
        _id:uuid(),
        conversationId,
        senderId: user?._id,
        textMessage,
        username: currentChat.username,
        createdAt: new Date(),
        senderUsername: user?.username,
    };
     socket.emit("sendMessage", socketMessage);

//receiver side

useEffect(() => {
    let mounted = true;
    socket?.on("getMessage", (data) => {
        if (mounted) {
            setArrivalMessage({
                _id: data._id,
                conversationId: data.conversationId,
                senderId: data.senderId,
                textMessage: data?.textMessage,
                createdAt: data.createdAt,

            });
        }
    });

    return () => {
        mounted = false;
    };
}, [socket]);
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!