PDA

View Full Version : time variable



lankinator
07-15-2007, 07:02 PM
i have this code:

strftime("%d/%m/%y %H:%M",time())

the time() part returns the time for America (i think thats the server time).
Could anybody please provide a way of making the time() part return the time for london?


thanks :D

Twey
07-15-2007, 07:20 PM
In PHP5:
date_create('now', new DateTimeZone('BST'))->format("d-m-Y G:i");

lankinator
07-15-2007, 07:56 PM
could it be in: PHP, PHP3, and PHTML scripts?

as the sever only supports them...

thetestingsite
07-15-2007, 08:07 PM
As long as the server has PHP 5+ installed, it can be whatever extension you want to make it (as long as it is parsed as a PHP script).

lankinator
07-16-2007, 03:02 PM
could it be in: PHP, PHP3, and PHTML scripts?

as the sever only supports them...

alexjewell
07-16-2007, 03:05 PM
So basically you're saying PHP5 is not installed on your server...

Twey
07-16-2007, 03:55 PM
That's fine, the .php extension will handle it (it's probably PHP4).

mwinter
07-16-2007, 04:20 PM
could it be in: PHP, PHP3, and PHTML scripts?

The extension of a PHP script doesn't in any way define the version of PHP in use: PHP 5 can quite easily parse a file ending ".php3".

If you want to be useful, actually state what version of PHP your host uses. This information is normally available in the response headers. This can also be found in the document generated by the phpinfo (http://uk.php.net/manual/en/function.phpinfo.php) function, and from the phpversion (http://uk.php.net/manual/en/function.phpversion.php) function.

lankinator
07-16-2007, 05:27 PM
as the sever only supports them...

i stated there that it only has php3, php, phtml installed :confused:

twey, i get the following error:
[b]Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in \\192.168.0.16\webfiles\files\2007-1\1253297\user_pages\user.php on line 1[/b[

mwinter
07-16-2007, 05:36 PM
i stated there that it only has php3, php, phtml installed :confused:

No, you stated what file extensions will effect parsing as PHP on your server. That has no bearing on what version of PHP is installed.



twey, i get the following error:
Parse error: parse error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' in \\192.168.0.16\webfiles\files\2007-1\1253297\user_pages\user.php on line 1

This is due to the failings of PHP as a language: the DateTime object needs to be assigned to a variable before one of its methods can be called.



$date = new DateTime('now', new DateTimeZone('BST'));
echo $date->format('d-m-Y G:i');

Twey
07-16-2007, 06:20 PM
Hm, it worked for me using date_create() as in the code I posted. I initially used new DateTime(), but switched to date_create() because of that issue.

mwinter
07-16-2007, 06:32 PM
Hm, it worked for me using date_create() as in the code I posted.

I could have sworn that it didn't for me, though I think one might as well be consistent and use the OO form on both occasions.

It's possible that the OP is using PHP 4, hence the error, but I don't have that installed at the moment. I'm leaving soon, so it'll either have to wait until later or tomorrow.

If nobody's noticed, the PHP Group have announced the end of PHP 4 support at the end of this year. Critical updates will end 8th August, 2008.