A component to handle date and time.
This documentation is available in english | français.
You can help by translating this documentation; contact me for the the doc source.
Version : 0.5
Author : Leo West
Licence : GPL - Send me a mail if you enjoy this component!
Download date-0.5.zip
You should unzip and install Date/date.php in your shared PHP librairies directory,
for example /usr/lib/php or /home/www/lib.
There may be some methods i have not documented yet, see the source :)
Create a new Date instance.
The optional parameter timestamp is provided to set the Unix timestamp (number of seconds since 1/1/1970)
By default, the date is initialized with current date & time.
Construit un objet date a partir d'une chaine au format iso-8901.
$date = Date::fromDatetime( "2001-08-01T12:30:59" )
datetime est une chaine au format ISO comportant les parties date et heure
Retour un objet Date si ok, NULL si format non reconnu.
Le format ISO est YYYY MM DD "T" hh mm ss [TZ]
Le code de timezone optionnel TZ est ignoré dans cette version.
Accepte plusieurs variantes avec ou sans séparateur:
Set the hours, minutes, seconds fields
Shortcut to set all time fields at once. seconds are optional, 0 is assumed
Set the year, month of year, day of month, day of week fields.
The day of week is a number between 0 (sunday) and 6 (saturday). You may use the WDAY_* constants defined, see § Constants.
When both setDay() and setWeekday() are called, the last call takes over.
Return the Unix timestamp (number of seconds since 1/1/1970)
Return the year field
Return the month field
Return the day (in the month) field
Return the day of the week field, from 0 for sunday to 6 for saturday
Return the day in the year (1-366)
Return the hours field
Return the minutes field
Return the seconds field
Return the number of seconds elapsed since 00:00:00.
Return the number of days the current month has.
Add resp. years, months, days, hours, minutes to the current date.
$n is an integer and be negative to substract.
Overflows are handled automatically: if you add 2 days to a Date[ 30/12/2000 ], you'l obtain a Date[ 01/01/2001 ]
Compare the date with another.
Return a number of seconds representing the difference thisDate - otherDate
otherdate a valid Date object
if( $date1->compareTo( $date2 ) == 0 ) echo "date1 and date2 are equals";
Return the number of days between this date and otherDate, negative if otherDate is before thisDate.
otherdate a valid Date object
Return the date formatted according to the given format, using the same codes as strftime().
$time = $date->toString( "%H hours %M minutes %S seconds" );
See § Constants for some predefined formats.
A static method that format the given Unix timestamp according to format.
Usefull when you have many timestamps to format.
$today = Date::Format( "%a %d %m %Y", time() );
$yesterday = Date::Format( "%a %d %m %Y", time() - 86400 );
Some usefull constants are defined, for use with the setWeekDay (WDAY_*) abd toString (FMT_*) methods.
Symbol | Description | Value |
WDAY_SUNDAY | dimanche | 0 |
WDAY_MONDAY | lundi | 1 |
WDAY_TUESDAY | mardi | 2 |
WDAY_WENESDAY | mercredi | 3 |
WDAY_THURSDAY | jeudi | 4 |
WDAY_FRIDAY | vendredi | 5 |
WDAY_SATURDAY | samedi | 6 |
SEC_MINUTE | nombre de secondes dans 1 minute | 60 |
SEC_HOUR | nombre de secondes dans 1 heure | 3600 |
SEC_DAY | nombre de secondes dans 1 jour | 86400 |
FMT_DATEISO | format d'une date iso8601 | "%Y%m%dT%H%M%S" |
FMT_DATELDAP | format d'une date LDAP | "%Y%m%d%H%M%SZ" |
FMT_DATERFC822 | format d'une date RFC 822 (Mime) | "%a, %d %b %Y %H:%M:%S" |
FMT_DATEFR | date au format français (jj/mm/aaaa) | "%d/%m/%Y" |
FMT_DATEEN | date au format US (mm/jj/aaaa) | "%m/%d/%Y" |
FMT_TIME | heure au format hh:mm, sans les secondes | "%H:%M" |