Reputation: 812
When i insert date time in mongodb, It's in UTC format
ISODate("2016-03-29T07:53:02.847Z")
When i fetch this result, it's in IST
Tue Mar 29 2016 13:23:02 GMT+0530 (IST)
I want to convert it to EST and display (only date and time)
Tue Mar 29 2016 02:56:22 GMT-0400 (EDT)
Tue Mar 29 2016 02:56:22 ( final output )
I have tried node-time, moment js etc. Did a lot of research but no result. Any help/suggestions are appreciated.
Upvotes: 2
Views: 2647
Reputation: 338
Moment.js works in node.js and has timezone support that can convert from UTC to any desired timezone: http://momentjs.com/timezone/
var moment = require('moment-timezone');
var jun = moment("2014-06-01T12:00:00Z");
jun.tz('America/New_York').format('ddd MMM DD YYYY HH:mm:ss');
You'll need to npm install moment timezone first
npm install moment-timezone --save
Upvotes: 1