Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

135
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda