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

221
Views
admin.Firebase.Timestamp stores time 7 hours behind

I'm trying to store a timestamp in Firestore from Firebase Functions. However, the incorrect time is being recorded in Firestore.

For instance, I want to store the UTC time: August 14, 2021 21hr (9pm)

Note: this code is in my Firebase Function

const date = new Date(Date.UTC(
            csvRow.startDateYear,
            csvRow.startDateMonth,
            csvRow.startDateDay,
            csvRow.startDateHour,
            csvRow.startDateMinute
        ))

console.log(date); // prints 2021-08-14T21:00:00.000Z  (correct)

console.log('date.getTime():' + date.getTime()); // prints 1628974800000 (correct)

const timeStamp = admin.firestore.Timestamp.fromMillis(date.getTime());

console.log('timeStamp.toMillis():' + timeStamp.toMillis()); // prints 1628974800000 (correct)

write.startDate = timeStamp;

But when I actually look at the Firestore and see what's recorded, I get this, a timeStamp that's 7 hours behind:

enter image description here

I've also tried Timestamp.fromDate(date) but got the same result

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Firebase Firestore TimeStamps break apart when using hours because they do not have timezones built into them. They are meant to represent a greater period of time, not for specific timezones (hour).

Try this function and see if it works properly:

var myTimestamp = firebase.firestore.Timestamp.fromDate(new Date());

If you are attempting this with Cloud Functions try the following:

admin.firestore.Timestamp.fromDate()

Detailed documentation: https://firebase.google.com/docs/reference/node/firebase.firestore.Timestamp

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!