This is a discussion on Dates - back to basics. within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hello .. Occasionaly I realise that I take certain functionality for granted and don't understand it as well as perhaps ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hello ..
Occasionaly I realise that I take certain functionality for granted and don't understand it as well as perhaps I should. This is one of those times. Regarding the behaviour of integer timestamps - Can anyone tell me why the full dates returned [below] from two timestamps have different timezone offsets? <?php // the epoch. echo date('Y-m-d H:i:s O', 0); // prints "1970-01-01 01:00:00 +0100" // offset +1 hour // exactly two years later echo date('Y-m-d H:i:s O', 63072000); // prints "1972-01-01 00:00:00 +0000" // offset 0 ?> This seems pretty fundamental - any help is much appreciated. |
|
|||
|
I don't know what you've done to your computer, but I get:
1970-01-01 00:00:00 +0000 and 1972-01-01 00:00:00 +0000 dave. "Fabian Hore" <fabianhore@email.com> wrote in message news:QR4wd.771$qv4.299@newsfe1-win.ntli.net... > Hello .. > > Occasionaly I realise that I take certain functionality for granted and > don't understand it as well as perhaps I should. > This is one of those times. > > Regarding the behaviour of integer timestamps - > Can anyone tell me why the full dates returned [below] from two timestamps > have different timezone offsets? > > <?php > // the epoch. > echo date('Y-m-d H:i:s O', 0); > // prints "1970-01-01 01:00:00 +0100" > // offset +1 hour > > // exactly two years later > echo date('Y-m-d H:i:s O', 63072000); > // prints "1972-01-01 00:00:00 +0000" > // offset 0 > ?> > > > This seems pretty fundamental - any help is much appreciated. > > > > |
|
|||
|
On Thu, 16 Dec 2004 00:42:24 GMT, "Fabian Hore" <fabianhore@email.com> wrote:
>Occasionaly I realise that I take certain functionality for granted and >don't understand it as well as perhaps I should. >This is one of those times. > >Regarding the behaviour of integer timestamps - >Can anyone tell me why the full dates returned [below] from two timestamps >have different timezone offsets? > ><?php >// the epoch. >echo date('Y-m-d H:i:s O', 0); >// prints "1970-01-01 01:00:00 +0100" >// offset +1 hour > >// exactly two years later >echo date('Y-m-d H:i:s O', 63072000); >// prints "1972-01-01 00:00:00 +0000" >// offset 0 >?> > > >This seems pretty fundamental - any help is much appreciated. Searching on Google finds that the above result is in fact correct. From 1968 to 1972, the UK didn't change the clocks in winter. http://wwp.greenwichmeantime.com/inf...ightsaving.htm If you want to stick to GMT/UTC, you probably want to use gmdate(). -- Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk> <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool |
|
|||
|
But what about the fact that it doesn't do it all the time? On my machine,
both of your examples yielded the expected result - both +0000... "Fabian Hore" <fabianhore@email.com> wrote in message news:xtmwd.1385$Fz4.1155@newsfe4-gui.ntli.net... >>> Searching on Google finds that the above result is in fact correct. From > 1968 >>> to 1972, the UK didn't change the clocks in winter. > > Perfect. as long as I know why, I can sleep at night. > thanks > > > > > > |
|
|||
|
> But what about the fact that it doesn't do it all the time? On my machine, both of your examples yielded the expected result -
> both +0000... It depends on timezone settings on your system, which is used by "date" function (and other time manipulation functions). Hilarion |
|
|||
|
On Fri, 17 Dec 2004 11:32:09 GMT, "d" <d@example.com> wrote:
>But what about the fact that it doesn't do it all the time? On my machine, >both of your examples yielded the expected result - both +0000... Timezone settings. andyh@server:~/tmp$ echo $TZ Europe/London andyh@server:~/tmp$ php -q tz.php 1970-01-01 01:00:00 +0100 1972-01-01 00:00:00 +0000 andyh@server:~/tmp$ TZ=UTC php -q tz.php 1970-01-01 00:00:00 +0000 1972-01-01 00:00:00 +0000 -- Andy Hassall / <andy@andyh.co.uk> / <http://www.andyh.co.uk> <http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool |
|
|||
|
"d" <d@example.com> wrote in message
news:Zszwd.416$Qo4.13@fe1.news.blueyonder.co.uk... > But what about the fact that it doesn't do it all the time? On my machine, > both of your examples yielded the expected result - both +0000... > Adding the `T' token into your date format string shows whats going on. <?php echo "\n", date('Y-m-d H:i:s TO', 0); // "1970-01-01 01:00:00 BST+0100" echo "\n", date('Y-m-d H:i:s TO', 63072000); // "1972-01-01 00:00:00 GMT+0000" ?> This makes sense of Andy's first reply regarding the UK's clock changing nuance. On my system, the date() function is automatically selecting between British Summer Time and Greenwich Mean Time. I'd rather it didn't, so I guess there's a lesson here, Don't be flippant with timestamps. they're handy and portable but not without their caveats. A appropriate warning appears in the PHP docs in reference to the mktime() func. << This can be more reliable than simply adding or subtracting the number of seconds in a day or month to a timestamp because of daylight savings time. >> |