开发者

Convert UTC timestamp from database into Users Local time

Question: How do I Display a UTC timestamp from a databas开发者_运维百科e table in a users local time? Is there any way to do this with php?

Extra Context \/

I have an application that saves the date records are added to the database.I am saving the records in the database using mysql UTC_TIMESTAMP(). I then want to display the record to the user in their local time in my Smarty template.

{$dateAdded|smarty_modifier:"%D %R %Z"}

I have tried smarty, date_format as the modifier but I just get the UTC time and the persons timezone, which of course is correct but not the result that I want.

02/11/11 20:32 Pacific Standard Time

I need the time so be set to the user's local time

02/11/11 12:32 Pacific Standard Time

Is it correct to store the date of the transaction in UTC, and how do I display that UTC to the user in their local time? Is there a way to pull the date out of the database so that it is set to the users current local time?


You can use date_default_timezone_set() prior invoking the Smarty template. That defines directly how the UTC timestamps are adapted to the expected output timezone.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜