How to get exact IST time in php?

2019-05-07 16:16发布

In php, I used date function (eg: date('Y-m-d h-m-s')) it won’t displaying current time Please help me…

7条回答
混吃等死
2楼-- · 2019-05-07 16:19
if (function_exists('date_default_timezone_set'))
{
  date_default_timezone_set('Asia/Calcutta');
}
查看更多
家丑人穷心不美
3楼-- · 2019-05-07 16:22
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.

查看更多
在下西门庆
4楼-- · 2019-05-07 16:31
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
查看更多
SAY GOODBYE
5楼-- · 2019-05-07 16:38

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 minutes correctly. Use i for minutes not m:

date('Y-m-d h-i-s')

And make sure to echo it:

echo date('Y-m-d h-i-s');
查看更多
来,给爷笑一个
6楼-- · 2019-05-07 16:38

change your timezone according to ur need and then try

date('-r')
查看更多
聊天终结者
7楼-- · 2019-05-07 16:42

You want indian time.Here is my solution. You can use either Asia/Calcutta or Asia/Kolkata. both will return same time.

date_default_timezone_set('Asia/Calcutta');
echo date('Y-m-d h-i-s'); 

It worked for me.Try...

查看更多
登录 后发表回答