Determining a user’s timezone server side and converting from UTC has proven more trouble than its worth.
Is there a reliable way for javascript/jquery to determine the timezone of the user and apply the offset to a UTC datetime stamp (2012-08-25 10:59:56.511479) and output in my desired format (Aug 25 ’12 – 10:59AM)?
What might the jquery code look like to say
// dom ready
$('span.localtime').each(function(e) {
// get stamp and apply conversion
});
.getTimezoneOffset()is available on the date object, and gives you the offset from UTC in minutes.Thus:
Note that
myUtcDate.toString()could be replaced with any date formatting you want. In your case, it might look likeYou might want to use a date format plugin for formatting dates in a neater more reliable manner.