Created
December 10, 2012 19:40
-
-
Save dshaw002/4252814 to your computer and use it in GitHub Desktop.
Using Time Model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Saving time data into DB | |
$this->load->model('time_model'); | |
$user_id = $this->session->userdata('id'); | |
$user_timezone = $this->time_model->getTimeZone($user_id); | |
$format = "U"; // automatically saves it in unix format, this is just to show you that you can adjust format.... | |
$data['timestamp'] = $this->time_model->getUTCTimeStamp($user_timezone, $format); | |
Shorthand: $data['timestamp'] = $this->time_model->getUTCTimeStamp($this->time_model->getTimeZone($this->session->userdata('id')); | |
Converting time data to users timezone | |
$this->load->model('time_model'); | |
$timestamp = $this->db->query("SELECT timestamp FROM table WHERE user_id='$user_id'); | |
//params: 1-> timestamp(assumed in GMT), 2-> users timezone, 3-> time format as specified in date() | |
//http://php.net/manual/en/function.date.php | |
echo $this->time_model->convertTime($timestamp, $user_timezone, 'm-d-Y h:i:s'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment