How do i get correct time in nodejs?

long story short, i get correct time from browser js , bash terminal and python terminal but not from a nodejs repl. Can someone explain this to me?

How do i get node to use timezone specific time and not UTC? I have tried exporting TZ, but it doesnt work. Thanks.
Any info on this would help. Thanks!!

If you don’t tell it to do anything else, as in the example, it prints the result of toISOString, so the UTC time. The others are printing it with the localised offset, that’s their default.

Hello and thanks for replying @DanCouper ,
I figured out the toLocaleDateString() and toLocaleString() methods while waiting for a reply to my post. However, it’s not possible to extract date/day etc from those string using getDate/getDay etc. What do you suggest i do if I need locale time/date but i also want to play around with that date object?

It’s UTC, so it’s global standard time, and that’s just what it prints to the console as default if you just call it the way you have, it’s still exactly the same. In the other JS environments where you’ve new Date() it’s running (new Date()).toString() (which prints localised), in Node it’s running (new Date()).toISOString() (which prints UTC), it’s still the same thing, the core of the Date object is a number, which is a UTC timestamp

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.