Monday, 2 February 2015

Format Date

Format Date

This little function was a request from a user who wanted a PHP function to format a UNIX timestamp. The user also requested that the function have an option of defaulting to the current timestamp, then, set the time zone to the local time in Sydney Australia. You could of course set the default timezone to any timezone as specied in by thedate_default_timezone_set function.

<?php/**
 *
 * @Standard date format for site display
 *
 * @param INT UNIX timestamp
 *
 * @return string
 *
 */
function localDate($timestamp=null){
 if(
is_null($timestamp))
        {
        
$timestamp time();
        }
 
date_default_timezone_set("Australia/Sydney");
 return 
date('j F Y  g:i'$timestamp);
}
?>

0 comments:

Post a Comment