Date/Time Converter Class
Usage/Examples
Remember, you can convert almost any form
of date/time. It also accepts date/times
that don't have leading zeros (such as n/j/y). It works fine as long as
the numbers aren't bunched together like: 11908 (njy), (not even a human
can read that), but 11 9 08 or 11/9/08 or 11/9 08 will work.
Original Date | Original Mask | New Mask | Output | Syntax |
11/1/2008 17:40:00 | n/j/Y H:i:s | m/d/y G:i | 11/01/08 17:40 |
$obj = new Date_Time_Converter("11/1/2008 17:40:00", "n/j/Y H:i:s"); echo $obj->convert("m/d/y G:i"); //you may echo the return value of convert() |
11/20/2005 07:40:00 PM | m/d/Y h:i:s A | M jS, Y g:ia | Nov 20th, 2005 7:40pm |
$obj = new Date_Time_Converter("11/20/2005 07:40:00 PM", "m/d/Y h:i:s A"); $obj->convert("M jS, Y g:ia", true); echo $obj->date_time; //or if you set the 2nd argument in convert() to true, you can retreive the value from the public $date_time variable |
219 | nj | m/d | 02/19 |
$obj = new Date_Time_Converter("219", "nj"); //its
smart... it knows there's no such month as 21, so it must be 2 echo $obj->convert("m/d"); |
119 | nj | m-d | 11-09 |
$obj = new Date_Time_Converter("119", "nj"); //this
defaults to November 9th, not January 19th. echo $obj->convert("m-d"); |
11 20 2005 07:40:25 PM | m/d/Y h:i:s A |
F jS 'y, g:i:sa |
November 20th '05, 7:40:25pm |
$obj = new Date_Time_Converter("11 20 2005 07:40:25 PM", "m/d/Y h:i:s A"); echo $obj->convert("F jS 'y, g:i:sa"); |
Fri, Feb 9th, 2007 | D, M jS, Y | Y-m-d | 2007-02-09 | $obj =
new Date_Time_Converter("Fri, Feb 9th, 2007", "D, M jS, Y"); echo $obj->convert("Y-m-d"); //you may also provide the day of the week in "D" format (Sun, Mon, Tue) |
11:20 AM | g:i A | g:i a | 11:20 am |
$obj = new Date_Time_Converter("11:20
AM", "g:i A");
//time only |