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

101
Vistas
do maths with firebase timestamp

I am saving the Firebase server timestamp using serverTimestamp() in version 9. And then I need to do some maths, for example adding 3000ms. However it seems that serverTimestamp() reurns an object and therfore simply adding 3000 is impossible. So far I have dealt with this saving the timestamp in my database and then reading it. This way it works but it involves an extra read and write operation in the database just to get this value on JS.
Is there a way to transform the serverTimestamp object to a number directly on JS without involving writing and reading from the database?


code not working (cannot sum 3000 to an object):

var NewserverTime = serverTimestamp() + 3000;

Code working but the extra step of reading and writing in the databese seems not very elegant...

 set(ref(db, "/dabasepath"), {
    ServerTime: serverTimestamp()   
});

const firebaseRef = ref(db, "/databasepath");
onValue(firebaseRef, (snapshot) => {
          NewServerTime = snapshot.val() + 3000;  
 });
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There is no way to store-and-transform a server-side timestamp with a single write operation. To determine the server-side timestamp you'll always have to write-then-read it.

My common approach is to store the timestamp and the offset as separate fields, and then checking both fields in the query, or having a calculated "timestamp plus offset" field that is automatically updated from Cloud Functions (which causes only an extra write).

about 4 years ago · Juan Pablo Isaza Denunciar
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