Friday, June 24, 2016

Modifying Datetime

This class is used to modify a datetime format. The class name is DateTime and the file name is class.datetime.php. The class and the example can be downloaded here (2kb!). Below is the example of use:

<?php

    require_once(class.datetime.php);
    $time = time() - rand(0, 172800);
    $timeStr = DateTime::timeStampToString($time);
    
    echo "Compare $time to ", time(), : , DateTime::compareDates($time, time()), "<br /><br /> ";
    echo "$time to string: $timeStr<br /><br /> ";
    echo "$timeStr to time stamp: ", DateTime::timeStringToStamp($timeStr), "<br /><br /> ";
    echo "$timeStr as Y-m-D: ", DateTime::timeFormat($timeStr, Y-m-d), "<br /><br /> ";
    echo "$time as Y-m-D: ", DateTime::timeFormat($time, Y-m-d), "<br /><br /> ";
    echo "From $time to ", time(), as human readable: , DateTime::timeToHumanReadable(time() - $time), "<br /><br /> ";
    echo "$time as fuzzy time string: ", DateTime::fuzzyTimeString($time), "<br /><br /> ";

?>