XF 2.1 Template timezone issue

grantus

Active member
I'm having an issue with a template where I'm getting the date from my table's date column (stored in unixtime). I'm display the date like this: 2024/0113/ so January 13, for example.

The problem is that users that are not in same time zone don't show the proper date. Is this because Xenforo is changing it based on the user's time zone?

Is there a way to set the time zone in my template?
 
You can create a \DateTime object with an explicit time zone using date_from_format, and pass that to date instead:

HTML:
{{ date(date_from_format('U', $timestamp, 'Some/Time_Zone'), 'Y/m/d') }}
 
You can create a \DateTime object with an explicit time zone using date_from_format, and pass that to date instead:

HTML:
{{ date(date_from_format('U', $timestamp, 'Some/Time_Zone'), 'Y/m/d') }}
That makes sense and it's straightforward. I was trying to set it just within the template. :( Thanks!
 
Back
Top Bottom