I am using Firebase pagging and therefore i need current timestamp for queries database in firebase ? can anyone knows how to get current timestamp from system?
FirebaseFirestore.getInstance().collection("news")
.orderBy("timestamp",Query.Direction.DESCENDING)
.startAfter(timestamp) // for here i need current system timestamp..?? how can i??
.limit(4)
.get()
firebase.firestore.FieldValue.serverTimestamp()If you want the date value of firebase.firestore.FieldValue.serverTimestamp() you can use .toDate().
See FireStore Timesteamp.
If you want the current Date as a timestamp you can use the following
For Firebase Functions
import admin = require('firebase-admin');
const todayAsTimestamp = admin.firestore.Timestamp.now()
For local projects
import { Timestamp } from '@google-cloud/firestore';
const myTimestampAsDate = Timestamp.now()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With