How to make a DateTime string that changes depending on time zone?

I'm in the middle of writing a website, and I got this marvellous idea. I would have my contact page change depending on the time zone it was viewed from.

Examples:

When viewed in the local time-zone (GMT +1):

I can be reached between 08:30 and 17:30

When viewed in New York (GMT -5):

I can be reached between 03:30 and 12:30

In San Francisco (GMT -8):

I can be reached between 00:30 and 09:30

In Beijing (GMT +8):

I can be reached between 16:30 and 01:30

... You get the idea.

I'm not sure where I should start. I know of moment.js but I'm not sure if it's suitable for this purpose, 'specially considering the fact that I want this to be automatically determined by the user's current location.

I'm using Node.js with Express.js for the server, and jQuery on the client-side. Any help?

Answers


You can create Date object with UTC time and get local time from it.

// args are in UTC time
function toLocalTime(hours, minutes){
    var d = new Date(Date.UTC(0, 0, 1, hours, minutes, 0));
    return [d.getHours(), d.getMinutes()].map(function(x){
        return ('0' + x).slice(-2);
    }).join(':');
}

"I can be reached between " + toLocalTime(07, 30) + " and " + toLocalTime(16, 30)

Need Your Help

Fixed Bar like facebook/wibiya with jquery/YUI/prototype

jquery jquery-ui jquery-plugins yui scriptaculous

I was just wondering if any one knows of a good script to emulate a bar like wibiya or the facebook notification bar that used to appear at the bottom(just before the current facebook homepage chan...

How to avoid nested for-each loops?

java xml jaxb

I've got a class which should parse an XML file, like this: