views:

40

answers:

2

Hey,

I have a Date() object that contains a UTC date, which I need converted to the users local timezone. Does anybody know how I could do this? :-)

Thanks in advanced!

A: 

You could use Date.getTimezoneOffset() that returns the time difference between Greenwich Mean Time (GMT) and local time, in minutes.

A sample from W3 Schools

<script type="text/javascript">

var d = new Date()
var gmtHours = -d.getTimezoneOffset()/60;
document.write("The local time zone is: GMT " + gmtHours);

</script> 
Saul
+1  A: 

I usually create a new Date object and use the Date.setUTC* functions to copy the date information.

Radomir Dopieralski
There is a script that searches the page for dates formatted as a date microformat and replaces them with user's local version: http://features.sheep.art.pl/LocalTimeAndDate
Radomir Dopieralski
Thanks, if you look at the javascript at the bottom of http://twtm.in/lw you'll see what I ended up doing :-)
tarnfeld