Blue
Blue

Reputation: 1448

Firestore Cloud Function timestamp conversion

I'm trying to figure out how to convert the timestamp of an event (onCreate, onDelete etc) from its

timestamp: '2017-11-10T20:24:55.803055Z'

format into seconds since 1970. I'm wonder if I need to figure out how to parse the timestamp or if there is function I can call in my cloud functions to make it easier.

Upvotes: 0

Views: 1764

Answers (2)

Pablo
Pablo

Reputation: 104

the timestamp from firebase/firestore comes in this format

date: Timestamp {
seconds: 1582250739,
nanoseconds: 934000000}

to convert this values i use moment like @Doug said.

moment.unix(item.date.seconds).fromNow()

Upvotes: 1

Doug Stevenson
Doug Stevenson

Reputation: 317467

Cloud Functions doesn't have anything special to help you with date conversions. It's just running node.js in a managed environment.

I'd recommend looking into the moment module, which has all kinds of date and time utilities, especially parsing.

Upvotes: 2

Related Questions