Class?Date?{
????function?getTimestamp?($hour=false,?$minute=false,?$second=false,?$month=false,?$day=false,?$year=false)?{
????????if?($hour?===?false)??$hour??=?Date?("G");
????????if?($minute?===?false)?$minute?=?Date?("i");
????????if?($second?===?false)?$second?=?Date?("s");
????????if?($month?===?false)??$month??=?Date?("n");
????????if?($day?===?false)??$day??=?Date?("j");
????????if?($year?===?false)??$year??=?Date?("Y");
????????//?Server?time:
????????$s_time?=?mktime($hour,?$minute,?$second,?$month,?$day,?$year);
????????//?Get?offset
????????$offset?=?date('Z',?$s_time);
????????//?GMT?time
????????$g_time?=?$s_time?-?$offset;
????????//?Return?all?three?in?an?array
????????$return_arr?=?array('server_time'?=>?$s_time,?'gmt_time'?=>?$g_time,?'offset'?=>?-$offset);
????????return?$return_arr;
????}
????function?toMysqlDate($timestamp=''){
????????//?Array?passed??convert?server?time?and?gmt_time?in?array
????????if?(is_array($timestamp)?AND?isset($timestamp['server_time'])?AND?isset($timestamp['gmt_time']))?{
????????????$timestamp['server_time']?=?$this->toMysqlDate($timestamp['server_time']);
????????????$timestamp['gmt_time']?=?$this->toMysqlDate($timestamp['gmt_time']);
????????????return?$timestamp;
????????}?else?{
????????????return?date("Y-m-d",?$timestamp);
????????}
????}
????function?toMysqlDatetime($timestamp=''){
????????//?Array?passed??convert?server?time?and?gmt_time?in?array
????????if?(is_array($timestamp)?AND?isset($timestamp['server_time'])?AND?isset($timestamp['gmt_time']))?{
????????????$timestamp['server_time']?=?$this->toMysqlDatetime($timestamp['server_time']);
????????????$timestamp['gmt_time']?=?$this->toMysqlDatetime($timestamp['gmt_time']);
????????????return?$timestamp;
????????}?else?{
????????????return?date("Y-m-d?H:i:s",?$timestamp);
????????}
????}
????function?toTimestamp($mysql_datetime){
????????return?strtotime($mysql_datetime);
????}
????function?toTimezone?($timestamp,?$timezone,?$gmt_offset='')?{
????????//?Passed?an?array?
????????if?(is_array($timestamp)?AND?isset($timestamp['server_time'])?AND?isset($timestamp['gmt_time']))?{
????????????$gmt_offset?=?$timestamp['gmt_time'];
????????????$timestamp?=?$timestamp['server_time'];
????????}
????????//?No?GMT?timestamp?or?offset?passed??Get?it?automatically
????????//?Huge?chance?we'll?get?it?wrong?though?(i.e.?different?server?from?original?timestamp)
????????if?(empty($gmt_offset))?{
????????????$gmt_offset?=?$this->getTimestamp();
????????????$gmt_offset?=?$gmt_offset['offset'];
????????}
????????//?GMT?offset?or?timestamp?passed?
????????if?($gmt_offset?>?(24*3600))?{
????????????//?Timestamp?passed,?calculate?offset
????????????$gmt_offset?=?$timestamp?-?$gmt_offset;
????????}
????????//?Get?offset?of?timezone?(compared?to?GMT)
????????$original_tz?=?getenv('TZ');
????????putenv('TZ='?.?$timezone);?
????????$offset?=?date('Z',?time());
????????putenv('TZ='?.?$original_tz);
????????//?Calculate?time?in?new?timezone
????????$new_time?=?$timestamp?-?$gmt_offset?+?$offset;
????????return?$new_time;
????}
????function?toGmtTimezone?($timestamp,?$hours,?$gmt_offset='')?{
????????//?Passed?an?array?
????????if?(is_array($timestamp)?AND?isset($timestamp['server_time'])?AND?isset($timestamp['gmt_time']))?{
????????????$gmt_offset?=?$timestamp['gmt_time'];
????????????$timestamp?=?$timestamp['server_time'];
????????}
????????//?No?GMT?timestamp?or?offset?passed??Get?it?automatically
????????//?Huge?chance?we'll?get?it?wrong?though?(i.e.?different?server?from?original?timestamp)
????????if?(empty($gmt_offset))?{
????????????$gmt_offset?=?$this->getTimestamp();
????????????$gmt_offset?=?$gmt_offset['offset'];
????????}
????????//?GMT?offset?or?timestamp?passed?
????????if?($gmt_offset?>?(24*3600))?{
????????????//?Timestamp?passed,?calculate?offset
????????????$gmt_offset?=?$timestamp?-?$gmt_offset;
????????}
????????//?Calculate?time?in?new?timezone
????????$new_time?=?$timestamp?-?$gmt_offset?+?($hours*3600);
????????return?$new_time;
????}
}
?>