PDA

View Full Version : how do i auto adjust time base on user local time



tekboy
10-21-2006, 07:18 PM
how do i auto adjust time base on user local time

i want to put in a time like 1:00pm us time manually, how can i make this number automaticly change to whaterver time equivalent in user local timezone

----------
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
var time = "1:00 pm";
var time2 = "10:30 am";
</script>
</head>

<body>
<script>document.write(time)</script>
<script>document.write(time2)</script>
</body>
</html>

tech_support
10-22-2006, 04:55 AM
I don't think you can unless you use some sort of sophisticated IP-tracking to pin-point the country, find out the time zone and add it accordingly. Kind of expensive that is.

mwinter
10-22-2006, 01:25 PM
how do i auto adjust time base on user local time

The Date object already has the ability to adjust dates from UTC to local time, though it depends on the correct configuration of the user's computer.



i want to put in a time like 1:00pm us time manually, how can i make this number automaticly change to whaterver time equivalent in user local timezone

Adjust the target time to the equivalent UTC. For example, 1300 EST (USA: -5 hours) is 1800 UTC. If the target is a fixed date, use the Date.UTC method to obtain a timestamp, and then construct the Date object:



var date = new Date(Date.UTC(2006, 10, 1, 18)); // 2006-11-01 18:00:00

Note that months start at zero, so 10 is November, not October.

If the target is based on the current date, use the setUTCHours method to change the hours, minutes, seconds, and milliseconds:



var date = new Date(); // Current time and date

date.setUTCHours(18); // Additional arguments set minutes, seconds, and ms





I don't think you can unless you use some sort of sophisticated IP-tracking to pin-point the country, find out the time zone and add it accordingly.

IP addresses do not correspond to countries, nor does country necessarily determine the necessary local time adjustments (especially in the USA, for example).

Mike