Search code examples
javascriptnode.jsdatetimeutc

How to get UTC Date object in NodeJS?


I want to get the Current Date object in UTC. I tried using new Date(), Date.now() etc. But they return the local time. How do I get the UTC date object?

I want the Date object, not string representation.


Solution

  • Just use new Date(new Date().toUTCString())

    After converting to UTC, we have to again convert it into Date object if we need a Date Object.