0

My problem is that I can't seem to convert a UTC date to my user localtime in javascript.

Through Flask & Jinja I'm rendering a Datetime objet (naive, but it's a UTC datetime ) like "2013-01-01 17:30:00".

For example:

<p>The time is <span class="localtime">{{date}}</span></p>

I would like to display to my users the time in their localtime in the "HH:mm" format.

I tried using Jquery-Localtime but it doesn't seems to work. I always get 17:30 even when I change my computer time to test.

My end result should look like

The Time is 17:30 for a UK Users

and

The Time is 12:30 for a NY Users

Syl
  • 1,104
  • 2
  • 14
  • 22
  • This may help you out, http://stackoverflow.com/questions/8090549/how-to-get-user-timezone-using-jquery – Dom Jan 01 '13 at 20:55
  • 1
    Where are you parsing the date string? If you parse it in on the client side, it will use the local time zone, if you don't specify a timezone in the date string. – Manuel Leuenberger Jan 01 '13 at 20:59
  • A week ago I answer a question similar, take a look at http://stackoverflow.com/questions/14030137/i-need-change-the-jquery-program-into-javascript-with-same-output/14031257#14031257 – HMarioD Jan 01 '13 at 21:01
  • How will you know what time zone the user is in? You should just let the browser render a UTC time into whatever their configured time zone is. – Keith Jan 01 '13 at 21:05
  • How does the time look like before the Jquery-Localtime plugin changes it? From the docs I see one need to have a `Z` at the end of the datetime to have the plugin detecting the date, that is `2013-01-01 17:30:00Z` instead of `2013-01-01 17:30:00` – Clemens Klein-Robbenhaar Feb 10 '13 at 13:30

1 Answers1

0
var myDate = new Date();
var txtLocal = myDate.toLocaleDateString() +" " + myDate.toLocaleTimeString();
alert(txtLocal);
HMarioD
  • 784
  • 8
  • 18