PHP,Codeigniter:如何基于用户时区/位置在网络应用程序中全球设置日期/时间? [英] PHP, Codeigniter: How to Set Date/Time based on users timezone/location globally in a web app?

查看:504
本文介绍了PHP,Codeigniter:如何基于用户时区/位置在网络应用程序中全球设置日期/时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚意识到,如果我添加一个特定的记录到我的MySQL数据库 - 它将有一个日期/时间的服务器,而不是特定的用户和他们所在的位置,这意味着我的搜索功能按日期是无用的!因为他们无法在他们在时区添加时,而不是在服务器时区添加时进行搜索。



Codeigniter中有一种方法可以全局

$ b

$ b

我实际要求的是
可能如何使我的应用程序
依赖于每个用户的时区?


也许它更好地存储每个用户的时区在他们的个人资料,并有一个标准的时间(服务器时间),然后将时间转换为每个用户?



感谢所有

解决方案

我认为最简单的方法是定义内部数据存储的时区(您的服务器的时区或UTC)输出时根据用户的时区。



我不知道CodeIgniter,所以我不能指向正确的功能。一个知名的时区感知库是Zend_Date: 使用时区 我尚未使用这些功能,但他们看起来很有前途。



但是,一旦知道用户的时区,就不难



可能有相关问题:




I have just realised if I add a particular record to my MySQL database - it will have a date/time of the server and not the particular user and where they are located which means my search function by date is useless! As they will not be able to search by when they have added it in their timezone rather when it was added in the servers timezone.

Is there a way in Codeigniter to globally set time and date specific to a users location (maybe using their IP) and every time I call date() or time() that users timezone is used.

What I am actually asking for is probably how to make my application dependent on each users timezone?

Maybe its better to store each users timezone in their profile and have a standard time (servers time) and then convert the time to for each user?

Thanks all

解决方案

I think the easiest way is define a timezone for internal data storage (your server's time zone or UTC) and convert the time according to the user's time zone when outputting it.

I don't know CodeIgniter so I can't point you to the right functions. One prominent library that is timezone aware is Zend_Date: Working with Timezones I have not worked with these functions yet but they look promising.

However, once you know the user's time zone, it's not difficult to put together an own function that adds/substracts the offset when outputting dates and/or times.

Possibly related question:

这篇关于PHP,Codeigniter:如何基于用户时区/位置在网络应用程序中全球设置日期/时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆