0) { $time += date('Z'); } return $time; } /** * 将一个用户自定义时区的日期转为GMT时间戳 * * @access public * @param string $str * * @return integer */ function local_strtotime($str) { $timezone = isset($_SESSION['timezone']) ? $_SESSION['timezone'] : $GLOBALS['_CFG']['timezone']; /** * $time = mktime($hour, $minute, $second, $month, $day, $year) - date('Z') + (date('Z') - $timezone * 3600) * 先用mktime生成时间戳,再减去date('Z')转换为GMT时间,然后修正为用户自定义时间。以下是化简后结果 **/ // $time = strtotime($str) - $timezone * 3600; $time = strtotime($str); return $time; } /** * 获得用户所在时区指定的时间戳 * * @param $timestamp integer 该时间戳必须是一个服务器本地的时间戳 * * @return array */ function local_gettime($timestamp = NULL) { $tmp = local_getdate($timestamp); return $tmp[0]; } /** * 获得用户所在时区指定的日期和时间信息 * * @param $timestamp integer 该时间戳必须是一个服务器本地的时间戳 * * @return array */ function local_getdate($timestamp = NULL) { $timezone = isset($_SESSION['timezone']) ? $_SESSION['timezone'] : $GLOBALS['_CFG']['timezone']; /* 如果时间戳为空,则获得服务器的当前时间 */ if ($timestamp === NULL) { $timestamp = time(); } //$gmt = $timestamp - date('Z'); // 得到该时间的格林威治时间 //$local_time = $gmt + ($timezone * 3600); // 转换为用户所在时区的时间戳 $gmt=$timestamp; return getdate($local_time); } function WeekStart($first_day = 0,$getdate = "") { if(!$getdate) $getdate = date("Y-m-d"); //取得一周的第幾天,星期天開始0-6 $weekday = date("w", strtotime($getdate)); //要減去的天數 $del_day = $weekday - $first_day; //本週開始日期 $ws_day = date("Y-m-d", strtotime("$getdate -".$del_day." days")); $ws_stamp = strtotime("$getdate -".$del_day." days"); //本週結束日期 // $week_end_day = date("Y-m-d", strtotime("$week_start_day +6 days")); //上週開始日期 // $lastweek_start_day = date('Ym-d',strtotime("$week_start_day - 7 days")); //上週結束日期 // $lastweek_end_day = date('Ym-d',strtotime("$week_start_day - 1 days")); //返回開始和結束日期 return $ws_stamp; } function DayStart($getdate = "") { if(!$getdate) $getdate = date("Y-m-d"); //取得一周的第幾天,星期天開始0-6 $ws_stamp = strtotime("$getdate"); return $ws_stamp; } ?>