Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

137
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda