• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Each user can set timezone

#11
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

#15
I remember correctly using that function mentioned can result in odd behavior as it affects all users in that PHP process.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.