When I look at the log files for my application, the entries are listed in UTC. However, I want the entries to reflect my local timezone. Can you customize the time zone for a Node.js application?
Asked
Active
Viewed 316 times
0
-
http://stackoverflow.com/questions/10615828/how-to-use-timezone-offset-in-nodejs – data_henrik Aug 18 '16 at 16:39
-
@data_henrik - I've tried using moment and moment-timezone and all that comes back shows data in UTC with GMT+0000. – dr0711 Aug 18 '16 at 18:46
-
You can format the way moment and moment-timezone returns data. Here is an example: `var timestamp = moment().tz("America/New_York").format('MMMM Do YYYY, h:mm:ss a');` This will output: "August 18th 2016, 3:30:25 pm" There is more formatting ways described here http://momentjs.com/docs/#/displaying/format/ – Andrew Lohr Aug 18 '16 at 19:32
-
the problem is I don't know what the time zone is to pass into tz(). I need to get that first, then I can pass that in. How do you get the timezone? – dr0711 Aug 18 '16 at 20:18
-
You can use `moment.tz.names`. The information on the list of timezone names is here: http://momentjs.com/timezone/docs/#/data-loading/getting-zone-names/ – William 'Bill' Wentworth Aug 19 '16 at 19:38
-
@BillWentworth I tried using the moment.tz.names and it does bring back a list of the timezones. Mine always comes back as UTC and everything I try to do to bring back more information, like offset, comes back as 0. I just tried moment().toLocaleString() and this came back- Mon Aug 22 2016 13:37:17 GMT+0000. I am in Eastern Time and on Windows 10. I have the code in my app.js, its not in the html. I've also tried moment().format("Z") and this comes back with +00:00. – dr0711 Aug 22 '16 at 14:55