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

157
Visualizações
Document creation timestamp (server-time) in Firestore

I'm new to firebase and firestore, creating a single-page app, I was wondering how can I store the document creation time with the document, representing the server-side time. When I changed my system time to an incorrect time and then ran the code below, it was storing the same (incorrect) timestamp for both clientDate and serverTimestamp fields.

I tried the following (Firebase JavaScript SDK version 9.0.2):

import { addDoc, collection, Timestamp } from 'firebase/firestore';
import { db } from '../index';

export const storeSomething = async () => {
    const data = {
        clientDate: new Date(),
        serverTimestamp: Timestamp.now(),
    };
    
    const someCol = collection(db, 'somecollection');
    const docRef = await addDoc(someCol, data);
};
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The Timestamp.now() function returns the current client-side time, so is indeed sensitive to clock skew and manipulation.

To write a server-side timestamp, use:

  • in v9/modular syntax: serverTimestamp()

  • in v8/compat syntax: firebase.firestore.FieldValue.serverTimestamp()

  • in the Admin SDK: admin.firestore.FieldValue.serverTimestamp()

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