![](/bink.gif) |
|
| ![](/bink.gif) |
PHP ½Ã°£ °ü·Ã ÇÔ¼ö¸¦ ½á¼ ½Ã°£ Â÷ÀÌ °è»êÇϱâ, DATEDIFF |
|
|
![](icon/private_name/1.gif) |
13³â Àü |
½Ã°£ Â÷À̸¦ °è»êÇÏ°í À̸¦ Ãâ·ÂÇÏ´Â ÇÔ¼ö¸¦ ¸¸µé¾î º¸°í À̸¦ ÅëÇØ ½Ã°£ °ü·Ã ÇÔ¼ö date, strtotime »ç¿ë¹ýÀ» ¾Ë¾Æº¸µµ·Ï ÇսôÙ. ¾Æ·¡ PHP ¼Ò½º ÄÚµå´Â »ç¿ëÀÚ Á¤ÀÇ ÇÔ¼ö datetimediff ¸¦ È£ÃâÇؼ ÇöÀç ½Ã°£ ¶Ç´Â ƯÁ¤ ½Ã°£À» ±âÁØÀ¸·Î ÂüÁ¶ ½Ã°£°úÀÇ ½Ã°£Â÷¸¦ °è»êÇÏ°í Ãâ·ÂÇÕ´Ï´Ù.
[½Ã°£ Â÷ÀÌ °è»ê ½ÇÇà °á°ú]
2009-06-06 12:02:28
2009-06-06 09:11:04
2009-06-06 13:15:03
2½Ã°£ Àü
2½Ã°£ 51ºÐ 24ÃÊ Àü
4½Ã°£ 3ºÐ 59ÃÊ Àü
[½Ã°£ Â÷ÀÌ °è»ê PHP ¼Ò½º ÄÚµå]
<?
$ctime = date('Y-m-d H:i:s');
//$rtime = "1942-01-01 00:00:01";
//$rtime = "1941-05-19 09:00:00";
//$rtime = "20090606";
//$rtime = "20090606093924";
//$rtime = "2009-06-06 09:39:24";
$rtime = date('Y-m-d H:i:s', strtotime("-2 hours -51 minutes -24 seconds"));
$xtime = date('Y-m-d H:i:s', strtotime("+1 hours 12 minutes 35 seconds"));
echo "$ctime<br>\n";
echo "$rtime<br>\n";
echo "$xtime<br>\n";
echo datetimediff($rtime) . "<br>\n";
echo datetimediff($rtime, null, "ALL") . "<br>\n";
echo datetimediff($rtime, $xtime, "ALL") . "<br>\n";
function datetimediff($rtime, $ctime = null, $option = null){
if ($ctime) $cur_time = strtotime($ctime);
else $cur_time = time();
$ref_time = strtotime($rtime);
$cur_date = floor($cur_time / 86400);
$ref_date = floor($ref_time / 86400);
$datetimediff = $cur_time - $ref_time;
$datedist = $cur_date - $ref_date;
$datediff = floor($datetimediff / 86400);
$weekdiff = floor($datediff / 7);
$timediff = $datetimediff % 86400;
$hour = floor($timediff / 3600);
$min = floor($timediff % 3600 / 60);
$sec = floor($timediff % 3600 % 60);
$result = "";
if ($datedist>34) {
$result = date("Y³â n¿ù jÀÏ", $ref_time);
} else if ($weekdiff>0) {
$result = $weekdiff . "ÁÖ Àü";
} else {
if ($datediff>0) {
$result = $datedist . "ÀÏ Àü";
} else if ($timediff<=0) {
$result = "1ÃÊ Àü";
} else {
if ($hour) $result = $hour . "½Ã°£";
else if ($min) $result = $min . "ºÐ";
else $result = $sec . "ÃÊ";
if ($result) $result .= " Àü";
}
}
if ($option=='ALL') {
$result = "";
if ($datediff) $result .= ($result?" ":"") . $datediff."ÀÏ";
if ($hour) $result .= ($result?" ":"") . $hour."½Ã°£";
if ($min) $result .= ($result?" ":"") . $min ."ºÐ";
if ($sec) $result .= ($result?" ":"") . $sec . "ÃÊ";
$result .= " Àü";
}
return $result;
}
?> |
|
̵̧ : 971 |
̵̧
¸ñ·Ï
|
|
| ![](/bink.gif) |
|