2016-09-14 2 views
0

나는 25 분 전으로 오늘을 추가 한 날짜를 표시하는 tryed 조건시간 PHP를 확인하는 방법은 오늘과 어제 1 시간 미만으로 기능?

  • 시간 간격 미만 60분 경우 오후 5시 반 등

    $added_time = strtotime('1 Jan 2016 6:00 AM'); 
    $currentTime = strtotime('1 Jan 2016 7:15 AM'); // probably uses time() 
    $diff = timespan($time1, $time2); 
    
    if($diff < 1 hour){ // how to check 1 hour 
    //display minutes ago 
    } 
    else { 
    //display added time 
    } 
    

    -> 분 전

  • 시간 간격이 60 분 이상인 경우 오늘 → 오늘 6.00AM

  • 시간 간격이 60 분 이상인 경우 그러나 어제 -> 어제 그렇지 오전 6시

  • 정확히

어떻게 1 시간 미만, 오늘과 어제의 상태를 확인하기 위해 $added_time?

답변

0

이것은 특별히 CodeIgniter 질문이 아닙니다. 정확히 무엇을하고 있는지 확신 할 수 없지만,이 코드는 당신을 가까이에있게 할 것입니다.

$Added = new \DateTime(date('Y-m-d H:i:s', strtotime('1 Jan 2016 6:00 AM'))); 
$Current = new \DateTime(date('Y-m-d H:i:s', strtotime('1 Jan 2016 7:15 AM'))); 
$Diff = $Added->diff($Current , FALSE); 

$hours = $Diff->format('%H'); 
$mins = $Diff->format('%I'); 

if($Diff->invert == true){ 
    echo "Some hours $hours and minutes $mins ago "; 
} 
else if($Diff->invert == false){ 
    echo "Some hours $hours and minutes $mins into the future "; 
} 

참고 :

http://php.net/manual/en/class.datetime.php

http://php.net/manual/en/datetime.diff.php

관련 문제