How would I convert the following dateformat 2020-09-18T18:36:15.000Z
to Timestamp using the firebase-admin npm package
Asked
Active
Viewed 83 times
0

Frank van Puffelen
- 565,676
- 79
- 828
- 807

Coder3000
- 119
- 2
- 7
1 Answers
1
You can just use the fromDate
function like this:
import * as admin from 'firebase-admin';
const str = "2020-09-18T18:36:15.000Z";
const timestamp = admin.firestore.Timestamp.fromDate(new Date(str))
Check the documentation for further readings here.

PRSHL
- 1,359
- 1
- 11
- 30
-
How would I convert iso date format to UCT? – Coder3000 Jul 29 '22 at 12:25
-
I am getting a "Error: Value for argument "seconds" is not a valid integer" error – Coder3000 Jul 29 '22 at 12:28
-
which version of `firebase-admin` do you run? I tested it on `10.1.0` with my answer and it works just fine. – PRSHL Jul 29 '22 at 12:36
-
updated my answer with the `import` and the missing Z in the iso timestamp. – PRSHL Jul 29 '22 at 12:37
-
Updated my firebase-admin version and it worked now, thank you – Coder3000 Jul 29 '22 at 17:48