eval.in

Paste #1081921

PHP — PHP 5.6.23, pasted 3 months ago (json)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
<?php
  $saved_time="2019-03-09 14:25:20";
    $formated_saved_time = new \DateTime($saved_time);
    $current_time = new \DateTime();
    $interval = $current_time->diff($formated_saved_time);
  
      if (!empty($interval->format('%a'))){
       $time_difference=$interval->format('%a days ago');
        } elseif ($formated_saved_time->format('d') != $current_time->format('d')){
             $time_difference="yesterday";
             }elseif (!empty($interval->format('%h'))){
                     $time_difference=$interval->format('%h hr, %i min ago');
                     } elseif (!empty($interval->format('%i'))){
                              $time_difference=$interval->format('%i min ago');
                              } elseif (!empty($interval->format('%s'))){
                                $time_difference=$interval->format('%s sec ago');
                                } 
                                
echo "posted ". $time_difference." at ".$saved_time;    

Program Output

posted 4 hr, 12 min ago at 2019-03-09 14:25:20

OK (0.008 sec real, 0.007 sec wall, 14 MB, 44 syscalls)

Fork