PDA

View Full Version : gmdate


Dean B
04-13-1999, 10:36 AM
I'm still a little but puzzled as to why the gmdate call I use on my index page is still showing GMT 1 hour slow. I thought I understood when us over here in the U.K put our clocks forward earlier than you guys. But when you moved your clocks forward a couple of weeks back I thought GMT would be displayed correctly again but nope http://www.aota.net/ubb/frown.gif
Anyone ?



------------------
Regards, Dean.
**DMCity Web Board**
www.dmcity.com/cgi-bin/ubb/Ultimate.cgi (http://www.dmcity.com/cgi-bin/ubb/Ultimate.cgi)

Terra
04-13-1999, 11:20 PM
Rich of www.timezoneconverter.com (http://www.timezoneconverter.com) made a very good post/article concerning this...

Please refer to:
http://www.aota.net/ubb/Forum3/HTML/000239.html

--
Terra
--Time is sometimes your worst friend or best enemy--
FutureQuest

Rich
04-13-1999, 11:36 PM
Dean: The time displayed on your index page is the correct GMT (UTC) time.

------------------
Rich

"What time is it in _____?"
www.timezoneconverter.com (http://www.timezoneconverter.com)

Dean B
04-14-1999, 10:04 AM
Rich,
I've been studying your detailed posting all morning and have tried implementing your suggestions without success. I think it's a little bit beyond the basic knowledge of perl that I have. I think I'll just have to live with the clock being 1 hr slow ..

<edit>
I just looked at your converter Rich and it does indeed show GMT without DST. I think this is where I was getting confused. Which leads me to ask how I can amend my simple php line to reflect GMT with DST added. ATM I just use -
<? print(gmdate( "H:i" ));
print " GMT"
?>
</edit>

Dean.

[This message has been edited by Dean B (edited 04-14-99).]

Dean B
04-14-1999, 02:04 PM
Oky doky, I can now get the following to work -

#!/usr/local/bin/perl

print "Content-type: text/html\n\n";

use Time::Local;
my @dayofweek = (qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday));
my @monthnames = (qw(January February March April May June July August September October November December));
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday);
$ENV{TZ} = ':/usr/share/zoneinfo/Europe/London';
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = localtime(time);
print "$dayofweek[$wday] $mday $monthnames[$mon]\n";
print "$hour:$min U.K time\n";

www.dmcity.com/cgi-bin/test/time.pl (http://www.dmcity.com/cgi-bin/test/time.pl)

but I can't transfer this code to a PHP file. I get a parse error on the use Time::Local; line. Does this have to be substituted for something else ?
<edit>
Darn, I've also just noticed that when the minutes are less than 10 it doesn't place a 0 in front. (Time now is 18:9)
</edit>

Dean.
(Boy, is this fun or what.... http://www.aota.net/ubb/wink.gif)

[This message has been edited by Dean B (edited 04-14-99).]

Terra
04-14-1999, 03:01 PM
UTC/GMT does not follow Daylight Savings Time...

UTC is universal time in purest sense...

As far as <10, you will have to sprintf "%02d" that value...

e.g. $now=sprintf("%02d:%02d", $hour, $minute);

Or if you are feeling dangerous, you can use the POSIX module and pull in the stftime() function... Below is the syntax...

strftime

Convert date and time information to string. Returns the string.

Synopsis:
strftime(fmt, sec, min, hour, mday, mon, year, wday = 0, yday = 0, isdst = 0)

The month (mon), weekday (wday), and yearday (yday) begin at zero. I.e. January is 0, not 1; Sunday is 0, not 1; January 1st is 0, not 1. The year (year) is given in years since 1900. I.e. The year 1995 is 95; the year 2001 is 101. Consult your system's strftime() manpage for details about these and the other arguments.

The string for Tuesday, December 12, 1995.
$str = POSIX::strftime( "%A, %B %d, %Y", 0, 0, 0, 12, 11, 95, 2 );
print "$str\n";

--
Terra
--whoooo, power tools--
FutureQuest

Dean B
04-14-1999, 05:16 PM
Terra,
What can I say. Thx http://www.aota.net/ubb/smile.gif
I had played already with strftime after finding it on the PHP site but became a little unsure when it asked about the respective locales being installed on your system. No idea what the POSIX module is all though I'm sure I heard Data mention it on last nights Star Trek http://www.aota.net/ubb/wink.gif I'll give it a try ..

Dean.
ps. My head started to hurt earlier on so I dropped a good old CNC clock in as a temp measure. Least the **** thing now shows the same time as the rest of the clocks in my house http://www.aota.net/ubb/smile.gif

Dean B
04-18-1999, 07:24 AM
Terra,
When I try adding this -

<?
$str = POSIX::strftime( "%A, %B %d, %Y", 0, 0, 0, 12, 11, 95, 2 );
print "$str\n";
?>

I get a parse error on the first line ?

Dean.

Terra
04-18-1999, 02:41 PM
OOooops....

Ummm sorry for the confusion, POSIX is a Perl module, and not PHP3...

I'm not sure if PHP3 has a strftime(), you might have to build your own with sprintf()...

--
Terra
--Did I say that?--
FutureQuest

Rich
04-18-1999, 10:28 PM
Dean:

I just saw your posts. As Terra pointed out, you won't be able to use the 'use' statements since these are perl specific libraries. Since I haven't studied the php functions, I'm afraid I can't help you much. What you are looking for is a function that will allow you to retrieve the time given a specified timezone, or this would be more likely implemented by specifying the delta in hours from GMT.

Rich

Dean B
04-19-1999, 08:56 AM
Thx Rich. For the time being I'm sticking with the CNC clock set at GMT +0100 Changing the offset twice a year seems a much easier solution.

Dean.
--- Mountains out of mole hills are a speciality of mine ---

Rich
04-19-1999, 08:35 PM
If you are only displaying the time and do not care about the date, then you *could* automate your offset by doing something like:

if (date/time >= dst_start and date/time < dst_end) then adjust_1_hour else do_nothing;

If your dst_start and dst_end are at different date/times each year, you'll have to still update your code once each year, but at least you won't have to set your alarm to wake you up at 1:59 a.m. just to make the change http://www.aota.net/ubb/smile.gif

Rich