Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How set default timezone in node js for windows

I'm trying to set the time zone at the start of the application

set "TZ=UTC"
node main.js

But is not work:

// main.js

var tz = process.env.TZ;
var date = new Date();
console.log(tz, '||', date);

UTC Tue Nov 17 2015 21:41:29 GMT+0300

like image 944
Andrey Shiryaev Avatar asked Nov 17 '15 18:11

Andrey Shiryaev


People also ask

How do I get current timeZone in node JS?

To get the current browser's time zone, you can use the getTimezoneOffset() method from the JavaScript Date object. The getTimezoneOffset() returns the time difference, in minutes, between UTC time and local time.

What is default timeZone in JavaScript?

Sometimes, we may want to initialize a JavaScript date to a particular time zone. The default time zone is UTC.

What timeZone does date () use?

What time zone does the Javascript new Date() use? Date objects work with the number of milliseconds since The Epoch (Jan 1st 1970 at midnight GMT).


1 Answers

I published a small utility called set-tz which takes advantage of tzutil CLI command. When you call setTZ() it effectively changes your PC's timezone so beware-if you kill the process, you'll need to manually revert back after you're done-I am assuming you'r process is short-lived. If you don't kill your process, it will revert your original timezone back for you.

like image 140
Capaj Avatar answered Oct 01 '22 23:10

Capaj