Skip to content

Instantly share code, notes, and snippets.

@shameerc
Created May 21, 2011 11:02
Show Gist options
  • Select an option

  • Save shameerc/984438 to your computer and use it in GitHub Desktop.

Select an option

Save shameerc/984438 to your computer and use it in GitHub Desktop.
This can be used in formating date if the given format is smarty specific
<?php
public function formatDate($date, $dateFormat='', $timeFormat='')
{
$_dateMap = array ( '%B %e, %Y'=> 'F d, Y',
'%A, %B %e, %Y' => 'l F d, Y',
'%m/%d/%Y' =>'m/d/Y',
'%d/%m/%Y' => 'd/m/Y'
);
$_timeMap = array(
'%I:%M %p' => 'h:i A',
'%l:%I %p' => 'g:i A',
'%H:%M' => 'H:i'
);
$phpDateFormat = (isset($_dateMap[$dateFormat])) ? $_dateMap[$dateFormat] : '';
$phpTimeFormat = (isset($_timeMap[$timeFormat])) ? $_timeMap[$timeFormat] : '';
$format = $phpDateFormat . ' ' . $phpTimeFormat;
if($format){
$date = new DateTime($date);
return $date->format($format);
}
else{
return $date;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment