0

Here I am getting GMT Time as follow.

1520489880

Now I am getting This as

$myfinaldate = gmdate("d M H:i", $strtoDate);

So it will returns me GMT time. Now i want to convet it to IST(indian standard time).

where I stuck when I try

//Set timezone to india
date_default_timezone_set('Asia/Kolkata');
echo date('Y-m-d H:i:s');  

But this returns me current time not the time that I get in strtotime

Abdullah Ilgaz
  • 719
  • 1
  • 17
  • 39

3 Answers3

0

You need to pass the timestamp:

date_default_timezone_set('Asia/Kolkata');
echo date('d M H:i', $strToDate); // where $strToDate is 1520489880

Would produce the following value:

08 Mar 11:48
sorak
  • 2,607
  • 2
  • 16
  • 24
  • So no use of `gmdate("d M H:i", $strtoDate)` ?? –  Mar 08 '18 at 06:32
  • sure, they're the same – sorak Mar 08 '18 at 06:33
  • 1
    Maybe its not same @sorak. date is that the time returned is your time zone. and gmdate is that the time returned is Greenwich Mean Time (GMT). – TarangP Mar 08 '18 at 06:36
  • Oh, I was referring to the use of the variable. Yeah, you need to set the timezone to Kolkata, and gmdate implicitly sets it incorrectly. – sorak Mar 08 '18 at 06:38
0

You can convert GMT time to IST time using following ways :

1.

echo date('Y-m-d H:i:s',strtotime('+330 minutes', 0));

2.

date_default_timezone_set('Asia/Kolkata');
echo date('Y-m-d H:i:s');
Hiren Makwana
  • 1,976
  • 2
  • 13
  • 28
0

Changing default timezone is not such a good idea. Use DateTime class, any you don't need to worry about default timezone anymore...

$dt = new DateTime("@$strToDate");
$dt->setTimezone(new DateTimezone('Asia/Kolkata'));
echo $dt->format('Y-m-d H:i:s');

demo

Glavić
  • 42,781
  • 13
  • 77
  • 107