如何使用 PHP 获取语言环境
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2881038/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get locale using Php
提问by Ramakrishnan
How to get Locale using Php,I want to get the time zone based on the location, is there any possibility to get in php.
如何使用Php获取Locale,我想根据位置获取时区,是否有可能进入php。
I need to convert it to GMT and save Database.Again i need to Pull it back to UI with same time same time zone.
我需要将它转换为 GMT 并保存 Database.Again 我需要将它拉回相同时区的 UI。
采纳答案by bobince
You can't get the client's locale or timezone from the server side, and you can only make a guess at it from the client side, using JavaScript.
您无法从服务器端获取客户端的语言环境或时区,只能从客户端使用 JavaScript 进行猜测。
(You can get more locale information if the browser supports Java, but that's a bit of a pain and everyone hates applets.)
(如果浏览器支持 Java,您可以获得更多区域设置信息,但这有点麻烦,而且每个人都讨厌小程序。)
To handle timezones in a web application, store all your times as UTC timestamps, and convert them to text for on-page formatting using a user-chosen timezone. You can use methods like in this questionto guess at the timezone, but since this is not reliable you should also allow the user to explicitly choose timezone.
要在 Web 应用程序中处理时区,请将所有时间存储为 UTC 时间戳,并使用用户选择的时区将它们转换为文本以进行页面格式设置。您可以使用此问题中的方法来猜测时区,但由于这不可靠,您还应该允许用户明确选择时区。
回答by Pol
Using
使用
setlocale (LC_ALL,"0");
to get in the result the actual locale.
获得结果的实际语言环境。
回答by Sarfraz
You can use:
您可以使用:
date_default_timezone_set('Europe/London');
date_default_timezone_get; // Europe/London
or
或者
if (ini_get('date.timezone')) {
echo 'date.timezone: ' . ini_get('date.timezone');
}

