Welcome Guest, Not a member yet? Register   Sign In
Each user can set timezone
#11

(This post was last modified: 10-15-2019, 01:03 AM by mboufos.)

Hello, i guess your question has been answered.
I use this function ( from model) to convert any type of timestamp to the user date-time
PHP Code:
    function _set_timestamp($timestamp)
    {
        $timezone $this->input->cookie('_timezone');
        $dt = new DateTime();
        $dt->setTimezone(new DateTimeZone($timezone));
        $dt->setTimestamp(strtotime($timestamp));
        return $dt->format("H:i d-m-Y");
    

so i take the server timestamp and the user timezone ( i have it on cookie) and i return the correct time according to user timezone Smile

So i just keep the server timestamp+Database Timestamp the same and i just change the users.
Reply
#12

(10-15-2019, 12:58 AM)mboufos Wrote: Hello, i guess your question has been answered.
I use this function ( from model) to convert any type of timestamp to the user date-time
PHP Code:
    function _set_timestamp($timestamp)
    {
        $timezone $this->input->cookie('_timezone');
        $dt = new DateTime();
        $dt->setTimezone(new DateTimeZone($timezone));
        $dt->setTimestamp(strtotime($timestamp));
        return $dt->format("H:i d-m-Y");
    

so i take the server timestamp and the user timezone ( i have it on cookie) and i return the correct time according to user timezone Smile

So i just keep the server timestamp+Database Timestamp the same and i just change the users.

Don't need to use date_default_timezone_set?
Reply
#13

Well, i dont do it i dont want to have different time on server different on user and database, so i keep the timestamp the same and i just change the timestamp where it needs.
I am not sure if its 100% correct or not Smile
Reply
#14

(10-15-2019, 01:24 PM)mboufos Wrote: Well, i dont do it i dont want to have different time on server different on user and database, so i keep the timestamp the same and i just change the timestamp where it needs.
I am not sure if its 100% correct or not Smile

In fact, before answering about DataTime, I was already using it, but I was doing it in a different logic. Your response opened my mind to think better. Sorted out! Thank you guys.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB