基于浏览器区域设置/位置的自动日期格式


Automated date formatting based on browsers locale / location

我正在寻找解决方案在javascript或PHP格式的"日期"answers"时间"基于访问者的位置和地区设置。

例如

echo auto_format_date(time());

将为美国用户输出20-09-2011,为英国用户输出20/09/2011。


谢谢大家的回答。现在我面前有几个备选方案,我将等待一些投票,看看你认为哪种方法更受欢迎

在服务器端代码(PHP, ASP.NET…)中,您可以检查请求的Accept-Language HTTP头以检测客户端浏览器语言。

接收语言:http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html sec14.4

您可以阅读更多信息:http://www.w3.org/International/questions/qa-accept-lang-locales

你必须通过PHP Geolacator从Ip获取国家

and then use zned function: date_default_timezone_set('Europe/Berlin');

和当你创建日期:

$date = new Zend_Date();

echo $日期;

我自己发现了以下内容:

http://www.w3schools.com/jsref/jsref_tolocalestring.asp

可以帮助我在浏览器中将日期格式化为用户喜欢的格式。这是一个好的解决方案吗?

我找到了另一个答案,它依赖于日期

https://code.google.com/p/datejs/wiki/FormatSpecifiers

%x     preferred date representation for the current locale 
       without the time        "4/13/2008"
%X     preferred time representation for the current locale
       without the date        "12:53:05"