/************************************************
PHP Ver 5.1 이상일때 타임존 버그 해결.
************************************************/
$date_area = $date_area?$date_area:"Asia/Seoul";
if(function_exists("date_default_timezone_set"))
{
@date_default_timezone_set($date_area);
}
function datetimeFunc()
{
return true;
}
/**
* 시간포맷 년월일시분초
*/
function GetDatetime($format='Y-m-d H:i:s',$unixtime = '') {
if(!defined(TIME_UNIX)) {
define("TIME_UNIX",time());
}
$unixtime = $unixtime?$unixtime:TIME_UNIX;
return date("$format",$unixtime);
}
define("TIME_DATETIME",GetDatetime());
$GLOBALS["time_datetime"] = TIME_DATETIME;
$GLOBALS["time_date"] = GetDatetime("Y-m-d");
$GLOBALS["time_date_year"] = GetDatetime("Y");
$GLOBALS["time_date_month"] = GetDatetime("m");
$GLOBALS["time_date_day"] = GetDatetime("d");
/**
* datetime 관련
*/
function getDatetimeinfo($unixtime='')
{
if(!defined(TIME_UNIX))
{
define("TIME_UNIX",time());
}
$unixtime = $unixtime!=''?$unixtime:TIME_UNIX;
$arr_dayweek = Array('일','월','화','수','목','금','토');
$arr_dayweek_ch = Array('日','月','火','水','木','金','土');
$arr_datetime_keys = explode(",","Y,y,L,m,n,M,t,F,d,j,z,a,g,G,h,H,i,s,d,D,w,W");
$arr_datetime_info = explode(",",date("Y,y,L,m,n,M,t,F,d,j,z,a,g,G,h,H,i,s,d,D,w,W",$unixtime));
$arr_datetime = Array();
foreach($arr_datetime_info as $key=>$val)
{
$arr_datetime[$arr_datetime_keys[$key]] = $val;
}
$arr_datetime["dayweek"] = $arr_dayweek[$arr_datetime[w]];
$arr_datetime["dayweekch"] = $arr_dayweek_ch[$arr_datetime[w]];
$arr_datetime["U"] = $unixtime;
return $arr_datetime;
}
/**
* 기준시간부터 지정기간에 대한 시간
* $p 기간
* $w y:연도 m 월 d 일 t 시간 i 분
* $s -1 이전 1 이후
* $nt 기준일
*/
function getWithinDatetime($p,$w,$s,$nt="")
{
$nt = $nt==""?time():$nt;
$arr_now = getDatetimeinfo($nt);
switch($w)
{
case "y":
$p *= $s;
$aty = $arr_now[Y] + $p;
$atm = $arr_now[n];
$atd = $arr_now[j];
$att = $arr_now[G];
$ati = $arr_now[i];
$ats = $arr_now[s];
$_at = mktime($att,$ati,$ats,$atm,$atd,$aty);
$at = getDatetimeinfo($_at);
break;
case '"m"':
$count_y = floor($p/12)*$s;
$count_m = ($p%12)*$s;
$aty = $arr_now[Y]+$count_y;
$atm = $count_m+$arr_now[n];
$atd = $arr_now[j];
$att = $arr_now[G];
$ati = $arr_now[i];
$ats = $arr_now[s];
$_at = mktime($att,$ati,$ats,$atm,$atd,$aty);
$at = getDatetimeinfo($_at);
break;
case '"d"':
$p = $s*$p;
$_at = $nt+($p*86400);
$at = getDatetimeinfo($_at);
break;
case "t":
$p *= $s;
$_at = $nt + ($p*3600);
$at = getDatetimeinfo($_at);
break;
case "i":
$p *= $s;
$_at = $nt + ($p*60);
$at = getDatetimeinfo($_at);
break;
}
return $at;
}
/**
* 두 기간 사이의 시간($wh)차
* $wh / d : 일 / t : 시간
*/
function getDateDiff($startdate,$enddate,$wh="d")
{
$arr_startdate = explode(" ",$startdate);
if(count($arr_startdate) > 1)
{
$arr_startdate[1] = $arr_startdate[1]?$arr_startdate[1]:"00:00:00";
$arr_starttime = explode(":",$arr_startdate[1]);
$arr_startdate = explode("-",$arr_startdate[0]);
$stut = mktime($arr_starttime[0],$arr_starttime[1],$arr_starttime[2],$arr_startdate[1],$arr_startdate[2],$arr_startdate[0]);
}else
{
$stut = $startdate;
}
$arr_enddate = explode(" ",$enddate);
if(count($arr_enddate) > 1)
{
$arr_enddate[1] = $arr_enddate[1]?$arr_enddate[1]:"00:00:00";
$arr_endtime = explode(":",$arr_enddate[1]);
$arr_enddate = explode("-",$arr_enddate[0]);
$edut = mktime($arr_endtime[0],$arr_endtime[1],$arr_endtime[2],$arr_enddate[1],$arr_enddate[2],$arr_enddate[0]);
}else
{
$edut = $enddate;
}
$arr_wh = Array("d"=>86400,"t"=>3600);
$diff = floor(($edut - $stut)/$arr_wh[$wh]);
return $diff;
}
/**
* 유닉스 시간을 날짜 포맷으로
*/
function getDateToUnixtime($datetime)
{
$arr_date = explode(" ",$datetime);
$arr_time = explode(":",$arr_date[1]);
$arr_date = explode("-",$arr_date[0]);
$ut = mktime($arr_time[0],$arr_time[1],$arr_time[2],$arr_date[1],$arr_date[2],$arr_date[0]);
return $ut;
}