Search code examples
javascriptnode.jsgoogle-cloud-firestorefirebase-admin

How would I convert iso dateformat to timestamp using firebase admin


How would I convert the following dateformat 2020-09-18T18:36:15.000Z to Timestamp using the firebase-admin npm package


Solution

  • 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.