Search code examples
codeignitertimetimezonetimestamp

Wrong time now (Codeigniter)


I have a problem in relation with the time now in Codeigniter. I'm using the timespan function in codeigniter. I have to get the current time and it returns a wrong current time now. My date in my pc(as of now) is 2013-07-04 3:21 PM but when I do this:

$now = time(); 
$human = unix_to_human($now);
echo $human;

The output is 2013-07-05 12:20 AM. Why is that?


Solution

  • place this code at the top of your index.php (bootstrap file).

    if( ! ini_get('date.timezone') )
    {
       date_default_timezone_set('Asia/Dhaka');
    } 
    

    instead of 'Asia/Dhaka' use your own time zone. should do the work.