프로그램/php2015. 3. 10. 15:14

/* 날짜 형식 변환
$d : 날짜(0000-00-00 00:00:00)
$t : 변환형식( 1(기본):당일이면 00:00:00, 지난 날짜이면 00.00.00 )
반환 : 변환한 날짜
*/
function rtn_date_fm($d, $t=1) {
 if(!$d || strlen($d) != 19) return false;
 $rtn = false;

 switch ($t) {
  case 1:
   if(substr($d, 2, 8) == date("y-m-d")) {
    $rtn = substr($d, 11, 8);
   } else {
    $rtn = str_replace("-", ".", substr($d, 2, 8));
   }

   break;
  
  default:
   $rtn = false;
   break;
 }

 return $rtn;
}

 

 

사용법 예> 금일이면 "시분초(00:00:00)" 형식으로 변환

$date = date("Y-m-d H:i:s");    // 오늘 날짜(2015-03-10 15:03:42)

echo "<br />날짜 형식 변환 = " . rtn_date_fm($date); 

 

결과>

 

 

사용법 예> 지난 날짜이면 "년월일(00.00.00)" 형식으로 변환

$date = "2015-03-09 12:00:00";    // 어제 날짜

echo "<br />날짜 형식 변환 = " . rtn_date_fm($date); 

 

결과> 

Posted by 은둔고수
프로그램/php2014. 1. 16. 18:46

php.ini 파일을 연 후 date.timezone = asia/seoul 설정을 해 준 후 아파치(apache) 데몬을 재 시작한다.

 

 에러 내용 :

Warning: date(): It is not safe to rely on the system's timezone settings.You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in 에러 파일 경로 on line 1

 

php 5.3.x 버전 이후부터 date.timezone을 설정해야 한다. 더보기> php.ini 설정 파일 위치 찾기

Posted by 은둔고수