2
while($chat = $result->fetch_object()){

        // Returning the GMT (UTC) time of the chat creation:

        $chat->time = array(
            'hours'     => date('H',strtotime($chat->ts)),
            'minutes'   => date('i',strtotime($chat->ts))
        );

I'm using this code to display time alongside chat message. How can I change this code to display output time in IST timezone? Thank you

Sean
  • 33
  • 1
  • 8

2 Answers2

3

You've several ways to achieve this, a simple one is using date_default_timezone_set before date, i.e.:

date_default_timezone_set('Asia/Kolkata');
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
0

I don't recommend you to store that values and work with a specific timezone in your DB. Instead I strongly advise you to use the conversions just to show to your users the right time where they are, Stack already discussed about that. I know that you already solved your problem, I just want to give my two cents about that, if someone come to your question and decides use date_default_timezone_set or setting in INI.

Anyways, UTC seems to be a very stable candidate with good timezone translation support.

capcj
  • 1,535
  • 1
  • 16
  • 23