Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9111831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:35:41+00:00 2026-06-17T03:35:41+00:00

My app is logging certain user events for display in the UI. The timestamps

  • 0

My app is logging certain user events for display in the UI. The timestamps are being stored as dates in Mongo, which become JS Date object, with timezone information relative to the server’s timezone.

I’m using moment.js to format the dates, but since my users are in Australia and my app is hosted on Heroku (server timezone is UTC), the ‘local’ time that moment.js helpfully outputs aren’t what my users want to see.

Moment.js allows you to switch between UTC and ‘local’ time (on the server), but doesn’t seem to let you output in the context of a different timezone.

(Changing the server’s timezone not solve the underlying issue, it would also be wrong for some of my users.)

I have tried to use the node-time library to change the timezone on the date, which does work if I then simply output the timestamp using Date.toString(), but if the date is wrapped by Moment.js, it reverts back to the server’s timezone.

I could wrangle a solution by calculating the difference between user-local timezone and server-local timezone and modifying the date before it is formatted by Moment.js, but I am hoping there is either (a) a more elegant solution, or (b) a good library that will do this.

I could also output the dates in UTC and let a client-side library reformat them, but I would prefer to have a server-side solution.

Does anybody know of a good solution to this, or a library that fills this gap for Node.JS apps? Is there an established best practice for this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T03:35:42+00:00Added an answer on June 17, 2026 at 3:35 am

    I ended up figuring out how to use both the node-time and moment.js libraries to create a relatively elegant solution to this.

    I created a module moment_tz.js like such:

    var moment = require('moment'),
        time = require('time');
    
    exports = module.exports = function(t,z) {
        var tz = new time.Date(0, z);
        return moment(t).add('minutes', t.getTimezoneOffset() - tz.getTimezoneOffset());
    }
    

    It returns a moment object that has been updated with the difference (in minutes) between the two timezones.

    Here’s how I’d use it to output the current time in Sydney:

    moment_tz(new Date(), 'Australia/Sydney').format('Do MMM \'YY - h:mm:ss a')
    

    If anybody has a better solution, please let me know!

    Cheers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Rspec/Device/Cucumber template app Upon logging in I wish the user to be redirected
I'm developing an app that can be used without logging in immediately, but certain
My iPhone app started logging this error: lo->hi recycling invariant violated! followed by: Program
I have a Java app that can authenticate to LDAP by logging users into
I've just implemented Elmah for logging in my MVC3 app, and of course all
I want to unify the whole logging facility of my app. Any warning is
I'm looking into using a javascript logging framework in my app. I quite like
For debugging purposes, I would like my app to log to a java.util.logging.SocketHandler. Here's,
I have an project csproj, with app.config file, and logging Ent.Library section using configsource
I'm working with spring 3.0.6. My app has lot of places where logging added

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.