I'm having some trouble making a platform using CodeIgniter to echo out the time in a specific timezone. According to the CI docs, if I wanted to output the timestamp in EST with DST on, I would use something similar to the following:
$timezone = 'UM5';
$daylight_saving = TRUE;
My first thought was to just change the master time reference found in config.php
to UM5
- but that didn't make anything change.
At this point I'm pretty sure I need to insert those above mentioned variables somewhere in the PHP page that I'm working with. The problem is, I'm not quite sure where I need to insert them.
This is what the current page looks like:
<?php
class IG_Time extends CI_Model {
function __construct()
{
// Call the Model constructor
parent::__construct();
}
// return date and time in format selected by user
function GetDateTimeInFormat($datestamp, $format)
{
switch($format)
{
// Swatch Internet Time
case null:
case 1:
return date_format(date_create($datestamp), 'jS F, Y') . ' @' . date("B", human_to_unix($datestamp)) . ' .beats';
// Unix time
case 2:
return human_to_unix($datestamp);
// Time since
case 3:
return timespan(human_to_unix($datestamp), time()) . ' ago';
// Database
case 4:
return $datestamp;
// English
case 5:
return date_format(date_create($datestamp), 'jS F, Y, g:i a');
// American
case 6:
return date_format(date_create($datestamp), 'F jS, Y, g:i a');
}
}
}
I tried adding the $timezone and $daylight_saving variables directly under the opening
return date_format(date_create($datestamp,$timezone,$daylight_saving), 'F jS, Y, g:i a');
But that appeared to have broken the time completely, so I reverted back to it was by default.
Where would I need to place the $timezone and $daylight_saving variables and how should I use them trying to "return date_format".
Thanks in advance!
Put this code in index.php file on root
if( ! ini_get('date.timezone') )
{
date_default_timezone_set('UM5');
}