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

102
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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