특정시간으로부터 얼마나 지났는지
본문
특정시간으로부터 얼마나 지났는지 알수있는 코드가 있을까요?
가령 오늘 2020-01-30 일로부터 얼마의 시간이 지났는지 알수있는 코드가있을까요
답변 2
function get_time($datetime){ $past_timestamp = strtotime($datetime); $curr_timestamp = strtotime(G5_TIME_YMDHIS); $total_time = $curr_timestamp - $past_timestamp; $days = floor($total_time/86400); $time = $total_time - ($days*86400); $hours = floor($time/3600); $time = $time - ($hours*3600); $min = floor($time/60); $sec = $time - ($min*60); $return = ''; if($days>0){ $return = "{$days}일 전"; }elseif($hours>0){ $return = "{$hours}시간 전"; }else{ $return = "{$min}분 전"; } return $return; }
echo get_time('2020-01-30');
<?php
$now = new DateTime();
$from = new DateTime("2020-01-30");
$diff = $now->diff($from);
echo $diff->days;
답변을 작성하시기 전에 로그인 해주세요.