Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get current System Timestamp for Firebase? in Android Kotlin

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

1 Answers

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()
like image 108
Ferin Patel Avatar answered Oct 29 '25 20:10

Ferin Patel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!