Results 1 to 3 of 3

Thread: I want to insert local time & date in my site

  1. #1
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default I want to insert local time & date in my site

    Wednesday 25 May 2008*|*13:01*GMT+2*|*Cyprus-EU*
    I want to insert local time & date in my site , well zone is GMT+2 , below is correct for date , what about time ?

    Code:
    <script language="JavaScript" type="text/javascript"><!--
     var months = new Array("Jan", "Feb", "Mar","Apr", "May", "Jun", "Jul","Aug", "Sep", "Oct","Nov", "Dec")
     var weekdays = new Array("Sunday", "Monday", "Tuesday","Wednesday", "Thursday","Friday", "Saturday")
    
     var today = new Date()
    //-->
    </script>
    
    
    <script language="JavaScript" type="text/javascript"><!--
     // Today is Weekday, Month Day, Year  
     document.write(weekdays[today.getDay()], ", ",months[today.getMonth()], " ",today.getDate(), ", ",today.getFullYear())  
    //-->
    </script>

  2. #2
    Join Date
    Sep 2007
    Location
    Maui
    Posts
    642
    Thanks
    284
    Thanked 15 Times in 15 Posts

    Default

    This will work in php5 (not 4) to correct the time based on your timezone, but it is set when you load the page. If you want a live clock, you have to use something else.

    echo "Original Time: ". date("h:i:s")."\n";
    putenv("TZ=Cyprus-EU");
    echo "New Time: ". date("h:i:s")."\n";

    Anyway, it works for me. erin

  3. #3
    Join Date
    Oct 2004
    Posts
    425
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    This is correct(js) ?

    Code:
    <script type="text/javascript">
    
    var d = new Date();
    gmt=d.toUTCString();    // get  GMT Time/date 
    // document.write (d.toUTCString());
    var gmt2ms = new Date(gmt.valueOf()+60*60*1000*2); // add two hours in ms
    document.write(gmt2ms.toString());  //  write date as Sun, 25 May 2008 14:19:30 
    </script>
    What the
    x.valueOf()
    x.toString()
    do ?

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
  •