Mohit Gupta
Mohit Gupta

Reputation: 87

php date function return wrong time. why?

I am using IST in my code. for this thing I declared gloabal variable as below code

date_default_timezone_set('Asia/Kolkata');
$IST=date('Y-m-d H:i:s');
$config['IST']=$IST;

In my other files I am calling this variable as

$IST = $config['IST'];
$time = $IST;
echo " Current time is $time";

I am getting wrong time. If current time is 2015-02-03 15:41:14 it is showing 2015-02-03 16:41:14

How to fix this issue?

I have updated my server time zone to Asia/Kolkata.

Upvotes: 0

Views: 1393

Answers (3)

Mohit Gupta
Mohit Gupta

Reputation: 87

Thanks everyone for your valuable suggestions. I apologize. I did't check my server's clock. It was all about server's clock. Once I set my server's clock to correct time, issue resolved.

I apologize again and thanks again.

Upvotes: 0

Hritik
Hritik

Reputation: 722

Try using date_default_timezone_set('Asia/Calcutta');

Upvotes: 0

Bioukh
Bioukh

Reputation: 1968

'Asia/Kolkata' exists only since PHP 5.2.6. Which PHP version are you using ?

Upvotes: 1

Related Questions