Display localtime

This bit of Javascript converts a time into the local timezone.

See the Pen Localtime by Andrew Pasquale (@apasquale) on CodePen.

The pertinent bit is this, which creates a new date from the UTC time and converts it to the current timezone:

var options = { timeZoneName: 'short' };

$('#date').html( new Date( Date.UTC(2015, 12, 11, 18, 0))
.toLocaleTimeString('en-US', options)
.replace(/:\d+ /, ' ') );

Leave a Reply

Your email address will not be published. Required fields are marked *