Is there an existing CodeIgniter helper/library that uses PHP DateTime class?
Does anyone know of an existing CodeIgniter (CI 2.0) Helper (or Library) that I can use to help with date and time formatting for views? Maybe something that uses the PHP5 DateTime class?
Most of our data is in the typical GMT/UTC format within a MySQL database. We now need to set a User's timezone (part of our admin/auth/acl) and then display everything by their timezone setting. I assume this would be easy to do with a CI he开发者_运维知识库lper or perhaps a library. Any ideas?
PHP's DateTime Classes and functions are fully available in CodeIgniter. No Library/Helper required...
That kind of things is so specific that you'll have to make it yourself. See creating CI libraries and helpers.
I was actually facing the same problem with a project about a year ago, and I was working on CI too. I just ended up using php's DateTime and DateTimezone stuff. It was tricky at first, but a little bit of googling helped. Perhaps this would help?
http://blog.boxedice.com/2009/03/21/handling-timezone-conversion-with-php-datetime/
I don't use CI but I see it has a filter system. Implement a filter that issues a SET TIME_ZONE query on the DB connection before your controllers run. You'll get all the dates/times out of the database in the user's local time zone without having to make any changes to any controller, view or database code.
精彩评论