Malith Malith - 1 year ago 126
Node.js Question

How to get the local timezone from the system using nodejs

Is there a way to obtain the local timezone from the system (eg:- ubuntu) using nodejs?

I used moment.js to extract the date and time values. But couldn't find a way to extract the timezone as well.

Answer Source

I solved this using moment.js (

var moment = require('moment');
var offset = moment().utcOffset();
console.log(''.concat(offset < 0 ? "-" : "+",moment(''.concat(Math.abs(offset/60),Math.abs(offset%60) < 10 ? "0" : "",Math.abs(offset%60)),"hmm").format("HH:mm")));


I found a better solution using moment.js. Just use moment().format('Z')

which gives the output :


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download