I’ve created a app in yii. it’s working well but an issue m facing is timezone. I’m running this application on localhost on my development machine.
When I’m printing date and time using [color="#4169E1"]date[color="#000000"]([/color][color="#2E8B57"]“l, F dS h:i A T”[/color][color="#000000"])[/color][/color] function, but output time didn’t matching with my local time.
See:
output by php date() function is: [color="#FF0000"]Tuesday, August 14th 05:14 PM IST[/color]
and my system time is [color="#008000"]Tuesday, August 14th 01:44 PM IST[/color]
there is [color="#FF0000"]4:30[/color] hours difference.
PHP time should be match with my machine time.
Timezone that I’ve set is [color="#F4A460"]‘Asia/Kolkata’[/color]
Above all was working well when I was using [color="#483D8B"]LocalTime[/color] and [color="#483D8B"]DefaultDateTimeParser[/color]. [color="#483D8B"]LocalTime[/color] class that was I found on Yii Wiki.
I removed it because it uses PHP [color="#483D8B"]DateTime[/color] class and my server PHP version is 5.1.6.
I had the same problem some time ago, but i solved it only by adding the ‘timezone’ on yii config file (main.php). You can try and change the time zone on php.ini and then restart the web server.
I’ve created a static function in a class that was returning date as:
$format = "l, F dS h:i A T";
return date($format, strtotime(date($format))); // This was returning on some mixed conditions
/* Correct is */
return date($format, strtotime($date));