Date and time settings

Post non-phpwcms related topics here - but I don't want to see "hey check this or that other cms". Post if you have a point or worthwhile comment, don't post just to increase you post count!
Post Reply
Bijan Hemati
Posts: 191
Joined: Sun 9. Nov 2003, 00:18
Location: Austin, TX

Date and time settings

Post by Bijan Hemati »

If the web-server is in a different time-zone than the local machine, how do you adjust the time to compensate the difference?

Bijan
adriano
Posts: 165
Joined: Sun 16. Nov 2003, 15:24
Location: Bremerhaven
Contact:

Post by adriano »

Is this really important? If you show the time which is at the moment you look at the page, your time is the right time.

So, the local time at your computer should be shown. Doesn't it?
Fotos von Norddeutschland und der Nordseeküste
Photos of Northern Germany and the North Sea Coast:
http://www.wackernah.net
Bijan Hemati
Posts: 191
Joined: Sun 9. Nov 2003, 00:18
Location: Austin, TX

Post by Bijan Hemati »

Well, The php date function calculates the date and renders it for the computer or server that script is on.

If my service provider is not in the same time-zone as I am, I will see an incorrect date & time.
I know there is a way to include a script that adjusts the time-zone difference, but I don't know what that script is and where it should be used.

Regards,
Bijan
Bijan Hemati
Posts: 191
Joined: Sun 9. Nov 2003, 00:18
Location: Austin, TX

Post by Bijan Hemati »

I have found this info. http://us3.php.net/manual/en/function.gmdate.php
Is this what I need to use?
User avatar
DeXXus
Posts: 2168
Joined: Fri 28. Nov 2003, 06:20
Location: USA - Florida

Post by DeXXus »

Greetings Bijan!
I cannot tell if this would work or not because my server is in same time zone. It would interesting, if you felt like "experimenting", to try the script described at: http://martin.f2o.org/php/localtime. The "actual" script code is at: http://martin.f2o.org/download/localtime/localtime.php but, I'll list it here with several blank lines removed and "your URL" inserted. You could try saving it as "localtime.php" and then, try using the {PHP:scripts/localtime.php} replacement tag of phpWCMS somewhere in your template.
Since you are not rewriting your URL's (via mod_rewrite), it would appear to use the "alternative" method of appending ";offset=360" instead of "?offset=360". Not sure how it would affect Oliver's scheme for the frontend URL's. Anyways... here's
the code (I hope it works for you :roll: ):

Code: Select all

<?php
/* $Id: localtime.php,v 1.1 2002/07/29 23:32:41 shaggy Exp $ */
/*
Copyright (c) 2001, 2002 by Martin Tsachev. All rights reserved.
mailto:martin@f2o.org
http://martin.f2o.org

Redistribution and use in source and binary forms,
with or without modification, are permitted provided
that the conditions available at
http://www.opensource.org/licenses/bsd-license.html
are met.
*/

// you can start the session in the calling page too
session_start();

function set_timezone($offset) {
    if ($offset) {
        $offset = -$offset;
        $_SESSION['GMT_offset'] = 60 * $offset;
        $GMT_offset_str = ( $offset > 0 ) ? '+' : '-';
        $GMT_offset_str .= floor($offset / 60) . ':';
        $GMT_offset_str .= (($offset % 60) < 10 ) ? '0' . $offset % 60 : $offset % 60;
        $_SESSION['GMT_offset_str'] = $GMT_offset_str;
    }
}

function format_datetime($date) {
        return (date('j M Y g:ia', $date + $_SESSION['GMT_offset']) . ' GMT ' . $_SESSION['GMT_offset_str']);
}

function format_date($date) {
    return date('j M Y', $date);
}

/////////////////////////////////////////////////////////////////////////////////////

if (!isset($_SESSION['GMT_offset']) ) {
    $_SESSION['GMT_offset'] = 0;
    $_SESSION['GMT_offset_str'] = '';
}

if (isset($_GET['offset']) ) {
    $_SESSION['offset'] = $_GET['offset'];
    set_timezone($_GET['offset']);
}

if ( !isset($_SESSION['offset']) ) {
?>
  <script type="text/javascript">
  window.onload = setLinks

  function setLinks() {
    now = new Date()
    offset = now.getTimezoneOffset();

    for ( i = 0; document.links.length > i; i++ ) {
      with ( document.links[i] ) {
        if ( href.indexOf('http://www.carltonsclass.us/') == 0 ) {
          if ( href.indexOf('?') == -1 ) {
            href += '?offset=' + offset;
          } else {
            href += ';offset=' + offset;
          }
        }
      }
    }
  }
  </script>

<?php
}

?>
Bijan Hemati
Posts: 191
Joined: Sun 9. Nov 2003, 00:18
Location: Austin, TX

Post by Bijan Hemati »

Hi DeXXus,

Thank you for finding this script. The description of the script is exactly what I'm looking for.
But I haven't been able to get it to do what it says it would do. I know its probably me, not doing something right.
I will play with it to see if I can get it to work.

I don't know how you find these things. But you are great! :)

Thank you again.

Regards,
Bijan
User avatar
DeXXus
Posts: 2168
Joined: Fri 28. Nov 2003, 06:20
Location: USA - Florida

Post by DeXXus »

Bijan Hemati wrote:But I haven't been able to get it to do what it says it would do. I know its probably me, not doing something right.
Regards,
Bijan
This one is MORE likely NOT of YOUR doing! Even if it is "appending" to links correctly... it's hard to tell whether it might be affected by it's use as just a simple phpWCMS replacement tag, in the template, rather than as a PHP "include" statement in the "true" backend. I shouldn't have thrown you to "the wolves" of such a "fuzzy" solution :roll:
Bijan Hemati
Posts: 191
Joined: Sun 9. Nov 2003, 00:18
Location: Austin, TX

Post by Bijan Hemati »

I shouldn't have thrown you to "the wolves" of such a "fuzzy" solution
:) :D :lol:
Bijan Hemati
Posts: 191
Joined: Sun 9. Nov 2003, 00:18
Location: Austin, TX

Post by Bijan Hemati »

Hi DeXXus,

I found this PHP script that will allow you to adjust for the time difference.
I made a php file with the script and tested it by itself, on the server, to see if it actually adjusts the time, and it does.
But including the script in a template in phpwcms or jcal file did not give the same result.

Code: Select all

PHP Freaks.com
Get GMT Time Offset 
Submitted by: phpfreak - November 27th, 2002
--------------------------------------------------------------------------------
Code Snipplet: 

<? 
$hour = date("H"); 
$minute = date("i"); 
$seconds = date("s"); 
$day = date("d"); 
$month = date("m"); 
$year = date("Y"); 

$hour = $hour + 6; // This is the offset from the server time to your time. 

// mktime ( int hour, int minute, int second, int month, int day, int year [, int is_dst]) 

echo date ("H:m M-d-Y", mktime ($hour,$minute,$seconds,$month,$day,$year)); 
?> 
--------------------------------------------------------------------------------
Description:
This code will add or subtract the time of the server's hardware to whatever time you tell it to on your $hour +6; line.
Just one more thing to play with. :wink:
sputtnik
Posts: 14
Joined: Mon 13. Dec 2004, 07:33

Post by sputtnik »

I'm trying to offset the time on the articles that i'm posting... where would I put the above code? which file? thanks
Post Reply