Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2019-12-29 19:07:07

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 619
Website

Display times in specific timezone, not base on location.

Hi, I would like to display the posted and expires times in a specific timezone (Japan), is there an option for it please?
Currently it converts the times base on the visitor location, it is good that it work like that behind the scenes, but I would like to display the times in a fixed timezone please.
Since I can’t find an attribute for it in the docs, so I guess there is a need to create a variable and use PHP for it right?

Same goes for the dates please.

Last edited by THE BLUE DRAGON (2019-12-29 19:08:06)

Offline

#2 2019-12-29 20:04:21

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 619
Website

Re: Display times in specific timezone, not base on location.

This is what I got so far, but the output I’m getting is 01:00:00+09:00, instead of 10:00, how do I format it right please?
Also if there is a way to declare the timezone in general as global in the page header and not per article it will be much better please.

<txp:variable name="time_posted"><txp:posted format="%m/%d/%Y %H:%M:%S" /></txp:variable>

<txp:php>
        global $variable;

        $date = new DateTime($variable['time_posted']);
        $date->setTimezone(new DateTimeZone('Asia/Tokyo'));
        $variable['time_posted'] = $date->format('H:i:sP');
</txp:php>

<txp:variable name="time_posted" />

Offline

#3 2019-12-29 21:06:54

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,578
Website

Re: Display times in specific timezone, not base on location.

Check what you have set in Admin › Preferences › Site under Time Zone. I thought that determined the timezone reporting and not the visitor’s timezone. Perhaps you could also post the relevant part from the Diagnostics where your server timezone should also be reported.


TXP Builders – finely-crafted code, design and txp

Offline

#4 2019-12-29 21:27:14

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 619
Website

Re: Display times in specific timezone, not base on location.

Thanks, this is my server timezone Server timezone: America/Chicago, the issue is that the localhost and the live server are in different timezones and it changed all the dates and times that I have set in my localhost.

Offline

#5 2019-12-29 23:04:08

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,578
Website

Re: Display times in specific timezone, not base on location.

THE BLUE DRAGON wrote #320751:

the issue is that … it changed all the dates and times … when transferring from localhost to live server

Yes, that can happen if they don’t match. Have you tried setting “Time Zone” in Textpattern’s Admin › Preferences › Site on your localhost version to the time zone of the target production server, i.e. to “Asia/Tokyo”?


TXP Builders – finely-crafted code, design and txp

Offline

Board footer

Powered by FluxBB