Results 1 to 3 of 3

Thread: how do i auto adjust time base on user local time

  1. #1
    Join Date
    Apr 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how do i auto adjust time base on user local time

    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>

  2. #2
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    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.
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by tekboy
    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:

    Code:
    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:

    Code:
    var date = new Date();  // Current time and date
    
    date.setUTCHours(18);  // Additional arguments set minutes, seconds, and ms

    Quote Originally Posted by tech_support
    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
    Last edited by mwinter; 10-22-2006 at 01:30 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •