I am developing web application. The application has different users from different countries.
I have used to manage thier registrations using UTC timestamp. It works fi
You need do few steps.
In this way, you can maintain the records along their creator's timezone.
As far as expiring records based on timezone then you can check based on their timezone.
Suppose I am in Pakistan and timezone is 5+. So expiry step should also follow my timezone.
/**
* @function getusertimezonedifference return timezone difference with UTC
* @param integer $timezonedifference optional
* @return string time
* @Comment Get User TimeZone Difference
*/
public function getusertimezonedifference($timezone = "Asia/Kolkata", $changetoUTC=false, $flg_array=false)
{
#$timezone = "Asia/Kolkata";+5.30
#$timezone = "America/Anchorage";-9
#$timezone = "America/Los_Angeles";-8
#$timezone = "America/Dawson_Creek";-8
#$timezone = "America/Chicago";-6
#$timezone = "America/New_York";-5
#$timezone = "America/Halifax";-4
#$timezone = "America/St_Johns";#3.30
$dayLightFlag = false;
$system_timezone = date_default_timezone_get();
$local_timezone = "UTC";
date_default_timezone_set($local_timezone);
$local = date("Y-m-d H:i:s");
date_default_timezone_set("GMT");
$gmt = date("Y-m-d H:i:s");
date_default_timezone_set($timezone);
$required = date("Y-m-d H:i:s");
date_default_timezone_set($system_timezone);
$diff1 = (strtotime($gmt) - strtotime($local));
$diff2 = (strtotime($required) - strtotime($gmt));
if($changetoUTC) {$diff2 = (-1*$diff2);}
// extract hours
$hours = floor($diff2 / (60 * 60));
// extract minutes
$divisor_for_minutes = $diff2 % (60 * 60);
$minutes = floor($divisor_for_minutes / 60);
// extract the remaining seconds
$divisor_for_seconds = $divisor_for_minutes % 60;
$seconds = ceil($divisor_for_seconds);
//create string HH:MM:SS
$ret = $hours.":".(($minutes>9)?$minutes:"0$minutes").":".(($seconds>9)?$seconds:"0$seconds");
if($flg_array){$ret = array($hours, ((abs($minutes)>9)?$minutes:"0$minutes"), ($seconds>9)?$seconds:"0$seconds");}
return ($ret);
}