Reputation:
I need to get current Indian time from my server located in US-Texas.
I have stored time as UTC timestamp. I am trying this way.
date_default_timezone_set('UTC');
echo date('O').'<br>';
echo date("F j, Y, h:i:s a", time()+(330*60)).'<br>';
I get correct time on my local server.
+0000
September 12, 2015, 10:59:53 am
and this on remote server.
+0000
September 12, 2015, 11:19:14 am
Please see and suggest why time is not same from remote server.
Upvotes: 1
Views: 87
Reputation: 3615
You are giving the time a strange offset to the time with the +(330*60)
bit. That is not the right way to do it.
Try
date_default_timezone_set("Asia/Calcutta");
echo date("F j, Y, h:i:s a", time() ).'<br>';
Or Try
ini_set( 'date.timezone', 'Asia/Calcutta' );
echo date("F j, Y, h:i:s a", time() ).'<br>';
Upvotes: 0
Reputation: 2568
time()
function is returning GMT time. try to use echo (new DateTime())->format('r');
instead
Upvotes: 1
Reputation: 1833
Why not directly set your default time zone to Asia/Calcutta
?
http://php.net/manual/en/timezones.asia.php
Upvotes: 0