Date and time settings
Posted: Tue 3. Feb 2004, 04:23
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
Bijan
The phpwcms support forum will help to find answers to your questions. The small but strong community is here since more than 10 years.
https://forum.phpwcms.org/
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
}
?>
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" solutionBijan 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
I shouldn't have thrown you to "the wolves" of such a "fuzzy" solution
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.