Use Firestore Timestamp with Firebase Admin SDK in Next.js
Explanation of how to use Firestore Timestamp in Next.js with Firebase Admin SDK. This method is not only for Next.js, but also for Node.js and React.
2025-7-1
Version
- firebase-admin: 13.4.0
Note
This article explains how to get the Firestore Timestamp from Firebase Admin, but if you use Firebase Firestore in v9 or later, please refer to the following link.
Usage
import { FieldValue } from "firebase-admin/firestore";
// Example
const data = {
createdAt: FieldValue.serverTimestamp(),
};
Convert to Date type
You can convert to JavaScript's Date type by using toDate()
.
const data = {
createdAt: data.createdAt.toDate(),
};
console.log(data.createdAt);
// 2025-07-01T04:09:41.665Z