Source for file example.php
Documentation is available at example.php
<title>Date Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
span.code { font-family:Monospace; }
echo '<span class="code">' . $ps_date . "</span><br />\n";
<h4>Object is set to currrent time and local time zone by default:</h4>
echo_code($date->format ('%d/%m/%Y %H.%M.%S%O (%Z)'));
echo_code($date->format2 ('DD/MM/YYYY HH.MI.SSTZO (TZC - TZN)'));
<h4>Set date to 1st February, 1991:</h4>
$date->setDate ("1991-02-01 01:02:03");
echo_code($date->format ('%d/%m/%Y %H.%M.%S'));
echo_code($date->format2 ('DD/MM/YYYY HH.MI.SS'));
// Display day, month spelled out:
echo_code($date->format ('%A, %e %B %Y, %H.%M.%S'));
echo_code($date->format2 ('NPDay, NPDDth Month YYYY, HH.MI.SS'));
<h4>Time without padding (i.e. leading noughts), and with short year:</h4>
echo_code($date->format ('%e/%m/%y %h.%M.%S'));
echo_code($date->format2 ('NPDD/NPMM/YY NPHH.MI.SS'));
<h4>Conversion to another time zone:</h4>
$date->convertTZbyID ("Asia/Calcutta");
echo_code($date->format2 ('"Time zone ID:" TZR'));
echo_code($date->format2 ('"Time zone name:" TZN'));
echo_code($date->format2 ('"Time zone code:" TZC'));
echo_code($date->format2 ('"Time zone offset:" TZO'));
echo_code($date->format2 ('DD/MM/YYYY HH.MI.SSTZO (TZC)'));
<h4>Addition/Subtraction:</h4>
echo_code($date->format2 ('DD/MM/YYYY HH.MI.SS'));
echo_code($date->format2 ('DD/MM/YYYY HH.MI.SS'));
echo_code($date->format ('%d/%m/%Y %I.%M.%S %p'));
echo_code($date->format2 ('DD/MM/YYYY HH12.MI.SS am'));
<h4>Display micro-time:</h4>
$date->setSecond (3.201282 );
echo_code($date->format ('%d/%m/%Y %I.%M.%s'));
echo_code($date->format2 ('DD/MM/YYYY HH12.MI.SS.FFFFFF'));
<h4>Convert to Unix time:</h4>
echo_code($hn_unixtime = $date->format2 ('U'));
<h4>Convert Unix time back to Date object:</h4>
$date2 = new Date($hn_unixtime);
echo_code($date2->format2 ("DD/MM/YYYY HH.MI.SSTZO"));
<h4>Compare two times for equality:</h4>
if ($date2->before ($date))
echo "second date is earlier (because Unix time ignores the part-second)<br />\n";
if ($date2->equals ($date))
echo "dates are now the same<br />\n";
Documentation generated on Mon, 11 Mar 2019 15:55:00 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|