Created
May 21, 2011 11:02
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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