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.
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.
No comments:
Post a Comment