PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Cale O  >  Date Time Converter  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: Includes many date and time example conversions
Class: Date Time Converter
Convert dates and times between formats
Author: By
Last change:
Date: 6 years ago
Size: 3,699 bytes
 

Contents

Class file image Download
<?php

//require class file
require_once 'class.datetimeconverter.php';



/**
*
*
* To format a date or time, simply initialize the class and supply the original date/time and mask,
* then call the convert() function and supply the new mask/format.
*
*
*/



//
// The following is a list of example date/time conversions with this class.
// You can use many different date/time formats, you only need to provide the mask (as in the php date() function)
// Currently, d, j, S, D, m, M, n, o, Y, y, a, A, g, G, h, H, i, s are supported.
//
// Dates and times without leading zeros will also work too (example: 5/25/08 5:45pm)
//










//you can get the new date a few different ways...
//example: echo $obj->convert($new_mask);



//first, the convert() function will return the new date

$orig_date = "03/19/2008";
$orig_mask = "m/d/Y";
$new_mask = "n/j/y";

$obj = new Date_Time_Converter($orig_date, $orig_mask);
$new_date = $obj->convert($new_mask);


echo
"<b>Original Date/Time:</b> " . $orig_date;
echo
"<br>";
echo
"<b>Original Mask:</b> " . $orig_mask;
echo
"<br>";
echo
"<b>New Mask: </b>" . $new_mask;
echo
"<br>";
echo
"<b>New Date/Time: </b>" . $new_date;
echo
"<hr>";

//outputs 3/19/08






//or second, you can retreive it from the public date_time variable
//example: echo $obj->date_time;

$orig_date = "Apr 5th, 2008";
$orig_mask = "M jS, Y";
$new_mask = "Y-m-d";

$obj = new Date_Time_Converter($orig_date, $orig_mask);
$new_date = $obj->convert($new_mask);


echo
"<b>Original Date/Time:</b> " . $orig_date;
echo
"<br>";
echo
"<b>Original Mask:</b> " . $orig_mask;
echo
"<br>";
echo
"<b>New Mask: </b>" . $new_mask;
echo
"<br>";
echo
"<b>New Date/Time: </b>" . $obj->date_time;
echo
"<hr>";

//outputs 2008-04-05










$orig_date = "1:20 AM";
$orig_mask = "g:i A";
$new_mask = "H:i";

$obj = new Date_Time_Converter($orig_date, $orig_mask);
$new_date = $obj->convert($new_mask);


echo
"<b>Original Date/Time:</b> " . $orig_date;
echo
"<br>";
echo
"<b>Original Mask:</b> " . $orig_mask;
echo
"<br>";
echo
"<b>New Mask: </b>" . $new_mask;
echo
"<br>";
echo
"<b>New Date/Time: </b>" . $obj->date_time;
echo
"<hr>";

//outputs 01:20










$orig_date = "3 9 08";
$orig_mask = "n j y";
$new_mask = "Y, m d";

$obj = new Date_Time_Converter($orig_date, $orig_mask);
$new_date = $obj->convert($new_mask);


echo
"<b>Original Date/Time:</b> " . $orig_date;
echo
"<br>";
echo
"<b>Original Mask:</b> " . $orig_mask;
echo
"<br>";
echo
"<b>New Mask: </b>" . $new_mask;
echo
"<br>";
echo
"<b>New Date/Time: </b>" . $obj->date_time;
echo
"<hr>";

//outputs 2008, 03 09







$orig_date = "Fri, Feb 9th, 2007";
$orig_mask = "D, M jS, Y";
$new_mask = "m/d/Y";


$obj = new Date_Time_Converter($orig_date, $orig_mask);
$new_date = $obj->convert($new_mask);


echo
"<b>Original Date/Time:</b> " . $orig_date;
echo
"<br>";
echo
"<b>Original Mask:</b> " . $orig_mask;
echo
"<br>";
echo
"<b>New Mask: </b>" . $new_mask;
echo
"<br>";
echo
"<b>New Date/Time: </b>" . $obj->date_time;
echo
"<hr>";

//outputs 02/09/2007









$orig_date = "02/09/2007";
$orig_mask = "m/d/Y";
$new_mask = "D, M jS, Y";


$obj = new Date_Time_Converter($orig_date, $orig_mask);
$new_date = $obj->convert($new_mask);


echo
"<b>Original Date/Time:</b> " . $orig_date;
echo
"<br>";
echo
"<b>Original Mask:</b> " . $orig_mask;
echo
"<br>";
echo
"<b>New Mask: </b>" . $new_mask;
echo
"<br>";
echo
"<b>New Date/Time: </b>" . $obj->date_time;
echo
"<hr>";

//outputs Fri, Feb 9th, 2007






?>