Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

1.09.2018

Node js Timezone using Moment

There seems to be no better way of manipulating timezones in javascript. So far I found Moment.js library to be decent. I used it in my node.js projects.

Easy install: Assuming you have node/npm installed, to install moment js library run npm install moment from command line.

Straightforward code:

var moment = require('moment-timezone');
moment.tz.setDefault('America/Chicago'); // default is UTC if you don't set anything
var formattedDate = moment('2018-01-09').format('YYYY-MM-DD'); //formats and converts to the default timezone set above
console.log(formattedDate);

Simple and and easy to use. Have fun manipulating date-time in your javascript code.