Daylight Saving Time - What am I doing wrong here?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tom_jones
Forum Newbie
Posts: 3
Joined: Wed Oct 26, 2005 2:59 pm

Daylight Saving Time - What am I doing wrong here?

Post by tom_jones »

I'm trying to get the current time for Sydney, but it's always 1 hour behind. The DST check evals false even though DST is in effect right now. The code is from Recipe 3.13 of the PHP Cookbook, btw.

Any ideas?

Code: Select all

<?php

// Find the current UTC time
$now = time();

// Sydney is 10 hours ahead
$now += 10 * 3600;

// Is it DST?
$ar = localtime($now,true);
if ($ar['tm_isdst']) { $now += 3600; }

// Use gmdate() or gmstrftime()
echo gmdate ('Y-m-d H:i:s',$now);

?>
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

The DST check is regarding your machine (if you are not in Sydney, you probably won't get the same result that you will get in Sydney).
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If your server is running in UTC, I don't think it will ever have DST enabled. GMT may, but it is in regard to the localized time, not the time you shift it to. You have to set the local timezone to the correct location to get the proper DST for that area (hopefully the code underlying is up to date.)

date_default_timezone_set() may be of interest if you're running PHP 5.1.
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

If you use PHP4, try this:

Code: Select all

putenv('TZ=-10');
For more information you can look in the comments of the putenv function.

P.S
Off the topic. How can I link to the PHP manual without writing the full url?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

ok wrote:Off the topic. How can I link to the PHP manual without writing the full url?
You mean like this? date()

viewtopic.php?p=252813#252813 :)
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

I read that you tested it only under FF 1.5.0.1, Does it work under FF2?

I don't see buttons (RTM?). :?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

It works in Fx 2.

An "RTM-ize" button should appear in the posting pages. On moderator screens it appears before the Syntax list box.
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

When running subSilver, it is appearing after the Syntax list box, but it still appears for me.

Greasemonkey's running yes? Check the paths that the script is set to execute on: Tools > Greasemonkey > Manage User Scripts.

There should be six urls:
posting.php*
http://devnetwork.net/forums/posting.php*
http://www.devnetwork.net/forums/posting.php*
privmsg.php*
http://devnetwork.net/forums/privmsg.php*
http://www.devnetwork.net/forums/privmsg.php*

With no exclusions.

If you continue to have problems, PM me.
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

I didn't notice that I need Greasemonkey. Thanks anyway.
Post Reply