Jump to content

Archived

This topic is now archived and is closed to further replies.

cows

date function problems

Recommended Posts

Hi,

I am pretty new to php and I have a problem I can't quite figure out.  I am not sure if I am misunderstanding the date() function or there is something else I am missing. 

I have this time stamp: [b]1159660803[/b]

In the time stamp converter it says [b]Sun, 1 Oct 2006 00:00:03 UTC[/b]

When i try get that from the date() function using

[code]date('l dS \of F Y h:i:s A',  1159660803);[/code]

I get a date/time and hour out ([b]Sunday 01st of October 2006 01:00:03 AM[/b])

I need to get the time in the time stamp, is there something I am doing wrong or not quite understanding?  The server is in the UK if that makes any difference.

Any help would be appreciated, I have spent all night trying to figure out what I am doing wrong. :(

Share this post


Link to post
Share on other sites
what output are you looking for exactly?

do you want this part: 01:00:03 AM

to look like this: 00:00:03 UTC

Share this post


Link to post
Share on other sites
use this excat code
[code] <? echo  date('i:s',  1159660803);?>[/code]

or if you need the hour in there use this:
[code]<? echo  date('h:i:s',  1159660803);?>[\code][/code]

Share this post


Link to post
Share on other sites
.. that doesn't solve his problem at all.

i imagine it's just a one-hour offset between server time and the timezone you expect it to be in.  try adding "O" (uppercase o) to your date() function and see if the server spits back UTC or if it's off of GMT.

Share this post


Link to post
Share on other sites
[url=http://www.php.net/date]http://www.php.net/date[/url]

e Timezone identifier (added in PHP 5.1.0) Examples: UTC, GMT, Atlantic/Azores

Share this post


Link to post
Share on other sites
keep in mind (as xsist's post itself says) that 'e' will only work for fairly new versions of PHP.

Share this post


Link to post
Share on other sites
Thank you.

I never realised the date function formatted the dates using the server's time zone settings and daylight saving settings.  I thought it would format the date as-is, UCT.

Is there anyway I can get the formatted date in UCT with that date function or another function?

Share this post


Link to post
Share on other sites
Read the manual entry at [url=http://www.php.net/date]http://www.php.net/date[/url]. If it doesn't help you then check out the posts below it. You'll normally find your solution in the user posted comments.


This may work....
[code]
<?php
echo date('D, j M Y h:i:s',  1159660803 - date('Z'));

// or

date_default_timezone_set('UTC');
echo date('D, j M Y h:i:s',  1159660803)

?>
[/code]

Share this post


Link to post
Share on other sites
[quote author=xsist10 link=topic=111620.msg452463#msg452463 date=1160988210]
This may work....
[code]
<?php
echo date('D, j M Y h:i:s',  1159660803 - date('Z'));

// or

date_default_timezone_set('UTC');
echo date('D, j M Y h:i:s',  1159660803)

?>
[/code]
[/quote]

The first solution worked perfectly.  Thank you very much.  I didn't want to use the date_default_timezone_set() because the server doesn't support that yet.

Thank you for all the replies, they are much appreciated.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.