Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Show different timezone

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
samuel95_54
Smarty n00b


Joined: 24 Jan 2016
Posts: 3

PostPosted: Sun Jan 24, 2016 10:46 pm    Post subject: Show different timezone Reply with quote

I'm using smarty template engine right now.

I'm wondering how display date and time from different timezone. Presently I store the EX: SENT DATE, into the database on UNIX Time format on the GMT timezone.

When I want to display the SENT DATE I put this code in the .TPL file.
Code:
{$message_search_result[i].MESSAGE_SENT_DATE|date_format:"$date_format %I:%M %p"}
This will output

Quote:
25/06/2014 06:00 PM

Inside the $date_format variable I have %d/%m/%Y

So how can I get this value to display depending on a selected timezone.
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Jan 25, 2016 1:02 am    Post subject: Reply with quote

You must set necessary timezone before passing control to Smarty.
Back to top
View user's profile Send private message
samuel95_54
Smarty n00b


Joined: 24 Jan 2016
Posts: 3

PostPosted: Mon Jan 25, 2016 3:38 am    Post subject: Reply with quote

What I think i'm gonna do calculate each time zone difference in seconde from the GMT. So it's gonna look like this.
Code:

{($message_search_result[i].MESSAGE_SENT_DATE$TIMEZONE)|date_format:"$date_format %I:%M %p"}


In the variable $TIMEZONE i'm gonna put EX : -3600

Do you think it's the best way to do it?
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Jan 25, 2016 9:38 am    Post subject: Reply with quote

http://www.smarty.net/forums/viewtopic.php?p=89886#89886
http://php.net/date_default_timezone_set

If you keep trying to invent wheels, obligatory facepalm will be added to the list.
Back to top
View user's profile Send private message
samuel95_54
Smarty n00b


Joined: 24 Jan 2016
Posts: 3

PostPosted: Mon Jan 25, 2016 12:48 pm    Post subject: Reply with quote

You were 100% right.

I wasn't know this function on php it's really easy integrate.

Thank a lot man you save me headache
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Mon Jan 25, 2016 4:17 pm    Post subject: Reply with quote

Just make sure you are using UTC times internally.
Then converting them to any other timezone will not be a problem.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP