Advertisement
reenadak

Format Date Unix

Feb 20th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.52 KB | None | 0 0
  1.     /*
  2.     - Format Date (Unix)
  3.     - Formats unix time (number of seconds passed since January 1st, 1970 to human
  4.       readable time like "January 1, 2015 at 3:35pm"
  5.      
  6.     $unixTime     - The time to be formatted (current time can be fetched with the php
  7.                     function time() )
  8.     */
  9.    
  10.     public function formatDateUnix($unixTime, $dateOnly = false) {
  11.         $formatted = date("F d, Y", $unixTime);
  12.        
  13.         if (!$dateOnly) {
  14.             $formatted .= " at ";
  15.             $formatted .= date("g:ia", $unixTime);
  16.         }
  17.        
  18.         return $formatted;
  19.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement