Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-04-22 18:34:20

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Help with getting local time with php please

I am moving my site to another server, in the US. I’m on GMT +1. So I thought that this code

<txp:php>
setlocale(LC_TIME, 'nl_NL');
$here= gmstrftime("%d %B %Y - %H:%M",time()+7200);
echo $here;
</txp:php>

would display my local time (+7200 because of DST). But the time displayed is still 4 hours behind. I understand that by using +21600 I can make the time display right, but is that the only way? I can’t seem to find my way in all those php date and time functions…

Also the visitor logs are 6 hours behind. The publish date is 4 hours behind.

Last edited by els (2007-04-22 19:47:55)

Offline

#2 2007-04-22 21:24:45

NeilA
Member
From: Blue Mountains, Australia
Registered: 2004-08-15
Posts: 316
Website

Re: Help with getting local time with php please

Isn’t this what the time zone setting in Admin >Preferences does?


Neil – Blue Mountains, Australia

http://westserve.org
http://ministrygrounds.net.au

Offline

#3 2007-04-22 21:28:58

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Help with getting local time with php please

NeilA wrote:

Isn’t this what the time zone setting in Admin >Preferences does?

Well, I’d expect that that would take care of the publish date and the logs dates (which it doesn’t, apparently). But I don’t think there is a txp tag for displaying today’s date and time, so I need the php code to do that.

Offline

#4 2007-04-22 21:49:51

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: Help with getting local time with php please

<txp:php>echo safe_strftime("%d %B %Y - %H:%M");</txp:php>

Alex

Offline

#5 2007-04-22 21:54:04

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Help with getting local time with php please

Thanks zem, but it gives me a time that is still 4 hours behind…

Offline

#6 2007-04-22 22:07:44

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: Help with getting local time with php please

safe_strftime() will use your Textpattern time zone setting. If it’s not using that correctly, try re-saving your prefs — that might be necessary if your server’s time zone has changed.


Alex

Offline

#7 2007-04-22 22:13:49

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Help with getting local time with php please

I understand what you say, and I did re-save the prefs several times, but the only way I can get your code to output my local time (and have the publish and logs dates right) is setting the TXP preferences to GMT +5 and DST enabled. It’s not a big deal, I don’t mind solving it like this. Must be something in the server settings then?

Offline

#8 2007-04-22 22:58:40

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: Help with getting local time with php please

No, Textpattern should compensate for the server time zone when you use safe_strftime(). It has no effect on the built-in strftime() and similar functions.

Last edited by zem (2007-04-22 22:59:21)


Alex

Offline

#9 2007-04-23 14:08:25

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Help with getting local time with php please

Very strange then, that I have to ‘upgrade’ my timezone with 4 hours… But never mind, it works this way.

Offline

#10 2007-04-25 22:17:46

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Help with getting local time with php please

This is very strange: today or yesterday apparently something happened with the server, because I lost some recent changes (a backup must have been restored), and guess what? safe_strftime works as it should :)

Offline

Board footer

Powered by FluxBB