0

I'm trying to get the current time, of a specific place/timezone, no matter where you are in the world. I am using Moment.js with Moment Timezone; and have come up with the following code:

$(document).ready(function() {
    var interval = setInterval(function() {
        var momentNow = moment().tz('Australia/Sydney').format('hh:mm:ss A');
        $('.time').html(momentNow);
    }, 100);
});

The only issue is that this is returning my current time where I am... not in Sydney, Australia. My end product would be to show the current time in Europe/London no matter where you were; so if you were viewing the site in America/New_York, it would return the current time in Europe/London. I have also set up a little timeout function so it auto updates.

Any ideas?

John the Painter
  • 2,495
  • 8
  • 59
  • 101
  • You'll need to work with moment.utc() - and edit it from there. Moment works in local time by default. You can find more information and examples here: http://stackoverflow.com/a/17856735/390421 – MartijnK Feb 25 '16 at 12:19
  • 1
    @MartijnK - That's true that moment works in local time be default, but here moment-timezone is being used correctly. There's no need to use `moment.utc()`. – Matt Johnson-Pint Feb 27 '16 at 06:59
  • @braw - Are you correctly loading both moment-timezone and the *data* for the time zones you're using? If so, your code looks fine to me. Could you put a jsFiddle or similar together showing the problem? Thanks. – Matt Johnson-Pint Feb 27 '16 at 07:01

0 Answers0