2012-06-19 3 views
1

나는 이렇게 dateformat을 strtotime하고 싶습니다 - Fri Jun 15 05:38:11 +1000 2012 어떻게해야합니까? $ago = time()-strtotime(Fri Jun 15 05:38:11 +1000 2012);을 다음이 할 - - 그래서 한 가지가 필요strtotime 이런 식의 날짜 형식

$ago = $ago/(60*60*24); 
echo $ago.' days ago'; 

을 - 기본적으로 내가 strtotime으로 필요하고 다음을 수행 한 strtotime 그것으로 작동합니다 (금 6월을 5시 38분 11초 1000 2012 15) 일해야합니다.

이 유형의 날짜가 strtotime 일 수없는 경우 어떻게 편집 할 수 있습니까? 그래서 strtotime이 될 수 있습니까?

+3

[이 참조가 (http://is2.php.net/manual/en/datetime.createfromformat.php) . – jadkik94

+1

? 그래서 Fri Jun 15 05:38:11 +1000 2012와 같은 날짜를 입력하고 '4 일 전'으로 되 돌리시겠습니까? –

+0

예, 정확히 :)! – y2ok

답변

0

차이점을 비교하고 floor/ceil을 사용하여 반올림합니다.

$now = time(); 
$then = strtotime($var); 

echo floor(($now - $then)/86400) . " days ago"; 
+0

건배! 너는 나의 날을 구했다!)! 최대한 빨리 받아 들일 것입니다. – y2ok

+2

Yikes! 'strotime ("Fri Jun 15 05:38:11 +1000 2012")'당신이 생각하는 * 것을 돌려 주나요? – Josh

0

DateTime::createFromFormat() 메서드를 사용하면 구문 분석 할 날짜 문자열의 형식을 정의 할 수 있습니다.

1

(절차 상당있어, OOP 스타일)이 시도 :

<?php 
$str = "Fri Jun 15 05:38:11 +1000 2012"; 

// From here: http://is2.php.net/manual/en/datetime.createfromformat.php 
$datetime = DateTime::createFromFormat('D M d H:i:s T Y', $str); 
$now = new DateTime(); 

// From here: http://is2.php.net/manual/en/datetime.diff.php 
$interval = $now->diff($datetime); 
echo $interval->format("%R%a days"); 
?>