³¯ÀÚ°è»ê - ½ÃÀÛÀÏ,¸¶°¨ÀÏ - °£°Ý°è»ê ÁÖ°£,ÀÏÀÚ,½Ã°£,ÃÊ ±îÁö |
|
|
 |
14³â Àü |
<?
dateTimeBegin =date("Y-m-d H:i:s"); //¿À´Ã³¯ÀÚ ¶Ç´Â ÁöÁ¤³¯ÀÚ ÀÔ·Â
$dateTimeEnd ="2005-12-07"; //¸¶°¨ÀÏ ÁöÁ¤
$aa=dateDiff($dateTimeBegin,$dateTimeEnd);
print" °ñ¶ó¼ ºÒ·¯¿À·Á¸é...
<li>text = $aa[0]
<li>weeks = $aa[1]
<li>days = $aa[2]
<li>hours = $aa[3]
<li>minutes = $aa[4]
<li>seconds = $aa[5]
";
// -----------------------------------------
function dateDiff($dateTimeBegin,$dateTimeEnd) {
$dateTimeBegin =strtotime($dateTimeBegin);
$dateTimeEnd =strtotime($dateTimeEnd);
if($dateTimeEnd === -1 || $dateTimeBegin === -1) {
# error condition
return false;
}
$diff = $dateTimeEnd - $dateTimeBegin;
if ($diff < 0) {
# error condition
return false;
}
$weeks = $days = $hours = $minutes = $seconds = 0; # initialize vars
if($diff % 604800 > 0) {
$rest1 = $diff % 604800;
$weeks = ($diff - $rest1) / 604800; # seconds a week
if($rest1 % 86400 > 0) {
$rest2 = ($rest1 % 86400);
$days = ($rest1 - $rest2) / 86400; # seconds a day
if( $rest2 % 3600 > 0 ) {
$rest3 = ($rest2 % 3600);
$hours = ($rest2 - $rest3) / 3600; # seconds an hour
if( $rest3 % 60 > 0 ) {
$seconds = ($rest3 % 60);
$minutes = ($rest3 - $seconds) / 60; # seconds a minute
} else {
$minutes = $rest3 / 60;
}
} else {
$hours = $rest2 / 3600;
}
} else {
$days = $rest1/ 86400;
}
}else {
$weeks = $diff / 604800;
}
$string = array();
if($weeks > 1) {
$string[] = "$weeks weeks";
} elseif ($weeks == 1) {
$string[] = "a week";
}
if($days > 1) {
$string[] = "$days days";
} elseif($days == 1) {
$string[] = "a day";
}
if($hours > 1) {
$string[] = "$hours hours";
} elseif ($hours == 1) {
$string[] = "an hour";
}
if($minutes > 1) {
$string[] = "$minutes minutes";
} elseif ($minutes == 1) {
$string[] = "a minute";
}
if($seconds > 1) {
$string[] = "$seconds seconds";
} elseif($seconds == 1) {
$string[] = "a second";
}
# ÃÖÁ¾ÀûÀ¸·Î ÇÔ¼ö¸¦ ¸ð¾Æ¼...---
$text = join(', ', array_slice($string,0,sizeof($string)-1)) . ", and ";
$text .= array_pop($string); # put the last one on after the and
return array($text, $weeks, $days, $hours, $minutes, $seconds);
}
?>
|
|
̵̧ : 304 |
̵̧
¸ñ·Ï
|
|