Reputation: 105
Thanks in advance. Actually i was using date('Y-m-d h:i:s', time())
and date("Y-m-d H:i:s")
to get the current date and time in php but it's not showing the proper time. Instead of showing proper Indian time it's showing some other time
My code is:
$today = date("Y-m-d H:i:s");
echo "Current date and time is ".$today;
Upvotes: 2
Views: 35356
Reputation: 3091
Try this, use date_default_timezone_set (Asia/Kolkata)
date_default_timezone_set("Asia/Kolkata");
$today = date("Y-m-d H:i:s");
echo "Current date and time is ".$today;
Upvotes: 3
Reputation: 882
date_default_timezone_set("Asia/Kolkata");
$today = date("Y-m-d H:i:s");
echo "Current date and time is ".$today;
This will help you to find your location: http://php.net/manual/en/timezones.asia.php
Upvotes: 2
Reputation: 16117
You need to use date_default_timezone_set
for set the specific time zone as:
if (function_exists('date_default_timezone_set'))
{
date_default_timezone_set('Asia/Mumbai'); // will set the mumbai timezone.
echo date('Y-m-d H:i:s');
}
This will help you to find your location: http://php.net/manual/en/timezones.asia.php
Upvotes: 1
Reputation: 96
Try this.
date_default_timezone_set('Asia/Kolkata');
echo date("Y-m-d H:i:s"); // time in India
Upvotes: 6
Reputation: 1427
You can use date_default_timezone_set
for set Indian time:
date_default_timezone_set('Asia/Kolkata'); //Indian time.
echo date('Y-m-d H:i:s');
Upvotes: 1