Showing posts with label Working with time. Show all posts
Showing posts with label Working with time. Show all posts

DateClass and DateSpanClass

This file, dateclass.php, consists of two classes, namely, DateClass and DateSpanClass.

DateClass allows you to add a period to a date. You can also retrieve periods such as begin/end of month, begin/end of week, and begin/end of quarters.

DateSpanClass allows you to determine the span between two dates. The span can be a wide variety of different kinds of periods including year, month, week, weekdays, & quarters.

These classes are written by Steve Powell and can be downloaded from phpclasses.org oe from here (60 kb).


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 />\n\n";
    echo "$time to string: $timeStr<br /><br />\n\n";
    echo "$timeStr to time stamp: ", DateTime::timeStringToStamp($timeStr), "<br /><br />\n\n";
    echo "$timeStr as 'Y-m-D': ", DateTime::timeFormat($timeStr, 'Y-m-d'), "<br /><br />\n\n";
    echo "$time as 'Y-m-D': ", DateTime::timeFormat($time, 'Y-m-d'), "<br /><br />\n\n";
    echo "From $time to ", time(), ' as human readable: ', DateTime::timeToHumanReadable(time() - $time), "<br /><br />\n\n";
    echo "$time as 'fuzzy' time string: ", DateTime::fuzzyTimeString($time), "<br /><br />\n\n";

?>


Counting Loading-Time

If we look at the top-right corner of google search result page, we see how fast is the search time (loading time). Maybe we want todo so to our web visitors to perform how fast is they access our web page. 

We can use wristwatch class to apply the loading time and you can download it from here 1kb (including an example of use) .