Skip to content

Instantly share code, notes, and snippets.

@Llewellynvdm
Last active March 2, 2018 02:36
Show Gist options
  • Save Llewellynvdm/e13ed45e73590cc4bcd98a73cf9305f1 to your computer and use it in GitHub Desktop.
Save Llewellynvdm/e13ed45e73590cc4bcd98a73cf9305f1 to your computer and use it in GitHub Desktop.
fancyDate
/**
* Change to nice fancy date (change was made)
*/
public static function fancyDate($date)
{
if (!self::isValidTimeStamp($date))
{
$date = strtotime($date);
}
return date('jS \o\f F Y',$date);
}
/**
* Change to nice fancy day time and date
*/
public static function fancyDayTimeDate($time)
{
if (!self::isValidTimeStamp($time))
{
$time = strtotime($time);
}
return date('D ga jS \o\f F Y',$time);
}
/**
* Change to nice fancy time and date
*/
public static function fancyDateTime($time)
{
if (!self::isValidTimeStamp($time))
{
$time = strtotime($time);
}
return date('(G:i) jS \o\f F Y',$time);
}
/**
* Change to nice hour:minutes time
*/
public static function fancyTime($time)
{
if (!self::isValidTimeStamp($time))
{
$time = strtotime($time);
}
return date('G:i',$time);
}
/**
* Check if string is a valid time stamp
*/
public static function isValidTimeStamp($timestamp)
{
return ((int) $timestamp === $timestamp)
&& ($timestamp <= PHP_INT_MAX)
&& ($timestamp >= ~PHP_INT_MAX);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment