cloudy

Author Topic: $timezone = date('T')  (Read 1447 times)

0 Members and 1 Guest are viewing this topic.

Offline jahuff

  • Posts: 769
  • Northern New Hampshire, USA
    • Weather Data Pittsburg, NH
$timezone = date('T')
« on: September 29, 2008, 11:36:41 AM »
Hi All,

I have just noticed that when I use "$timezone = date('T')" is displays CDT not Eastern time. It looks like I have WD and my computer set  correctly, any thoughts??

John

Offline Budgie

  • Martin
  • Global Moderator
  • Posts: 4,957
  • WML Station: WD00934 CWOP: CW7959
  • Isle of Lewis, Scotland
    • Hebrides-Weather
Re: $timezone = date('T')
« Reply #1 on: September 29, 2008, 12:08:59 PM »
Have you set the correct time zone in your Settings.php file?

Offline jahuff

  • Posts: 769
  • Northern New Hampshire, USA
    • Weather Data Pittsburg, NH
Re: $timezone = date('T')
« Reply #2 on: September 29, 2008, 01:08:51 PM »
Hi,

This what I have in the Settings.php "$SITE['tz']          = 'America/New_York';  //NOTE: this *MUST* be set correctly" to

John

Online TNETWeather

  • Kevin Reed (KrelvinAZ)
  • Global Moderator
  • Posts: 5,868
  • Gremlins are at work...
  • Mesa, AZ
    • TNET Weather Station - Mesa AZ
Re: $timezone = date('T')
« Reply #3 on: September 29, 2008, 01:29:40 PM »
What happens when you try:

"$SITE['tz']          = 'US/Eastern';

What version of PHP are you using?

All you need is Time, Aptitude and Desire ... and you can build just about anything...

Online TNETWeather

  • Kevin Reed (KrelvinAZ)
  • Global Moderator
  • Posts: 5,868
  • Gremlins are at work...
  • Mesa, AZ
    • TNET Weather Station - Mesa AZ
Re: $timezone = date('T')
« Reply #4 on: September 29, 2008, 01:32:47 PM »
BTW.. I use the following function to properly set the timezone feature:

This uses putenv for versions prior to 5.1.0 and date_default_timezone_set for versions 5.1.0 and higher.

Code: [Select]
function set_tz ($TZ){
    if (phpversion() >= "5.1.0") {
        date_default_timezone_set($TZ);
    } else {
        putenv("TZ=" . $TZ);
    }
}

I don't know what method the current templates use.

All you need is Time, Aptitude and Desire ... and you can build just about anything...

Offline jahuff

  • Posts: 769
  • Northern New Hampshire, USA
    • Weather Data Pittsburg, NH
Re: $timezone = date('T')
« Reply #5 on: September 29, 2008, 02:29:34 PM »
Hi,

I am using PHP5 (version 5.2.6). I tried  'US/Eastern'; but the same thing. hummmmmmm?

John

Offline saratogaWX

  • Posts: 4,672
  • Saratoga, CA, USA 37:16:28N, 122:01:23W - Elev: 374ft.
    • Saratoga Weather
Re: $timezone = date('T')
« Reply #6 on: September 29, 2008, 02:31:14 PM »
The current template and scripts (from me) all use the putenv("TZ=" . $TZ) method.

The PHP template does the setting in Settings.php (near the bottom of the page).  Other scripts which work either standalone or in the template may do the putenv() call again.

If this is an issue for PHP5 users, I can change the underlying code to support the date_default_timezone_set() call instead of putenv() for PHP installations that have the function available.

The last one to try is using EST5EDT for the spec.

Best regards,
Ken
Ken True
Saratoga Weather
CWOP: CW1792
WeatherUnderground: KCASARAT1
Free weather website PHP scripts and WD website AJAX templates

Offline jahuff

  • Posts: 769
  • Northern New Hampshire, USA
    • Weather Data Pittsburg, NH
Re: $timezone = date('T')
« Reply #7 on: September 29, 2008, 02:47:34 PM »
Hi Ken,

This code is at the bottom of Settings.php. "putenv("TZ=".$SITE['tz']);
$SITE['tzname']   = date("T",time());" I think I have the latest version of Settings.

John

Offline saratogaWX

  • Posts: 4,672
  • Saratoga, CA, USA 37:16:28N, 122:01:23W - Elev: 374ft.
    • Saratoga Weather
Re: $timezone = date('T')
« Reply #8 on: September 29, 2008, 03:39:24 PM »
That's the code, just replace it with
Code: [Select]
    if (phpversion() >= "5.1.0") {
        date_default_timezone_set($SITE['tz']);
    } else {
        putenv("TZ=" . $SITE['tz']);
    }
$SITE['tzname']   = date("T",time());

Thanks Kevin for the heads-up on PHP5 timezone setting.

Best regards,
Ken
Ken True
Saratoga Weather
CWOP: CW1792
WeatherUnderground: KCASARAT1
Free weather website PHP scripts and WD website AJAX templates

Offline jahuff

  • Posts: 769
  • Northern New Hampshire, USA
    • Weather Data Pittsburg, NH
Re: $timezone = date('T')
« Reply #9 on: September 29, 2008, 10:05:50 PM »
Hi Ken,

I inserted the code and I still get "CDT" Eastern Time and the time is also CDT. This is only on my new webcam History page

http://www.johnsnhweather.com/wxcam-history.php

Thanks,

John
« Last Edit: September 29, 2008, 10:14:21 PM by jahuff »

Offline saratogaWX

  • Posts: 4,672
  • Saratoga, CA, USA 37:16:28N, 122:01:23W - Elev: 374ft.
    • Saratoga Weather
Re: $timezone = date('T')
« Reply #10 on: September 29, 2008, 10:15:27 PM »
John, I think you have to use either 'America/New_York' or 'EST5EDT' as your choice for Eastern time zone.  I think it's still showing CDT because your webservers default timezone in CST6CDT and the 'America/Eastern' is not being recoginized.

Best regards,
Ken
Ken True
Saratoga Weather
CWOP: CW1792
WeatherUnderground: KCASARAT1
Free weather website PHP scripts and WD website AJAX templates

Offline jahuff

  • Posts: 769
  • Northern New Hampshire, USA
    • Weather Data Pittsburg, NH
Re: $timezone = date('T')
« Reply #11 on: September 29, 2008, 10:32:00 PM »
Hi Ken,

This is an interesting bug. I changed it to EST5EDT and it still shows CDT, but only in the body of the new http://www.johnsnhweather.com/wxcam-history.php page,

in the heading of that page the time is correct.

John


Offline saratogaWX

  • Posts: 4,672
  • Saratoga, CA, USA 37:16:28N, 122:01:23W - Elev: 374ft.
    • Saratoga Weather
Re: $timezone = date('T')
« Reply #12 on: September 30, 2008, 01:10:12 AM »
Maybe the wxcam-history.php page has an embedded putenv(); call in it that needs to be replaced too ?!?

Best regards,
Ken
Ken True
Saratoga Weather
CWOP: CW1792
WeatherUnderground: KCASARAT1
Free weather website PHP scripts and WD website AJAX templates

Offline jahuff

  • Posts: 769
  • Northern New Hampshire, USA
    • Weather Data Pittsburg, NH
Re: $timezone = date('T')
« Reply #13 on: September 30, 2008, 02:21:38 AM »
Thank you all the problem has been fixed, please see http://www.weather-watch.com/smf/index.php/topic,34454.msg282535.html#msg282535

John