Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

154
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!