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

155
Vistas
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 Respuestas
Responde la pregunta

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 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