Home > database >  How to correctly format date with timezone in date-fns?
How to correctly format date with timezone in date-fns?

Time:05-19

I am using date-fns library but It is not formatting the date correctly.

My code:

    import { format } from 'date-fns'
    console.log(format(endOfDay(new Date()), "yyyy-MM-dd'T'HH:mm:ssX"))

Required result:

      2022-05-19T23:59:59Z

Actual result:

      2022-05-19T23:59:59 02
        

Please help me in finding the mistake. Thank you

CodePudding user response:

To get your desired result using format...

import { format } from 'date-fns'

console.log(format(new Date(), "yyyy-MM-dd'T'HH:mm:ss'Z'"));
  • Related