php 如何在php中获得准确的IST时间?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5151185/
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 exact IST time in php?
提问by Kushal
In php, I used date function (eg: date('Y-m-d h-m-s')
) it won't displaying current time Please help me…
在 php 中,我使用了日期函数(例如:)date('Y-m-d h-m-s')
它不会显示当前时间请帮助我...
回答by Abhishek
You want indian time.Here is my solution. You can use either Asia/Calcutta
or Asia/Kolkata
. both will return same time.
你想要印度时间。这是我的解决方案。您可以使用Asia/Calcutta
或Asia/Kolkata
。两者都会同时返回。
date_default_timezone_set('Asia/Calcutta');
echo date('Y-m-d h-i-s');
It worked for me.Try...
它对我有用。试试...
回答by Sarfraz
Update:
更新:
Here is how you can set time zone for your region:
以下是为您所在地区设置时区的方法:
if (function_exists('date_default_timezone_set'))
{
date_default_timezone_set('Asia/Mumbai');
}
It should work fine. Note also that you have not specified minutescorrectly. Use i
for minutes not m
:
它应该可以正常工作。另请注意,您没有正确指定分钟。使用i
分钟不m
:
date('Y-m-d h-i-s')
And make sure to echo
it:
并确保echo
它:
echo date('Y-m-d h-i-s');
回答by Sreepal
if (function_exists('date_default_timezone_set'))
{
date_default_timezone_set('Asia/Calcutta');
}
回答by Prakash
You can try this:
你可以试试这个:
date('Y-m-d h-i-s',strtotime('+330 minute')); // where +330 min (difference of indian time zone with gmt)
回答by user957309
date_default_timezone_set('Asia/Kolkata');
// this sets time zone to IST
echo date_format(new DateTime(),'d M Y H:i:s');
// this gives you date and time
回答by user254153
date_default_timezone_set('Asia/kathmandu');
echo date('Y-m-d h-i-s');
This should work. You can see your timezone at http://www.worldtimezone.com.
这应该有效。您可以在http://www.worldtimezone.com 上查看您的时区。