Class DateTime
Representation of a date and time.
<?php
use ICanBoogie\DateTime;
date_default_timezone_set ('EST' );
$time = new DateTime('now' , 'Europe/Paris' );
echo $time ;
echo $time ->utc;
echo $time ->local;
echo $time ->utc->local;
echo $time ->utc->is_utc;
echo $time ->utc->is_local;
echo $time ->local->is_utc;
echo $time ->local->is_local;
echo $time ->is_dst;
echo $time ->as_rss;
echo $time ->as_db;
echo $time ->as_time;
echo $time ->utc->as_time;
echo $time ->local->as_time;
echo $time ->utc->local->as_time;
echo $time ->quarter;
echo $time ->week;
echo $time ->day;
echo $time ->minute;
echo $time ->is_monday;
echo $time ->is_saturday;
echo $time ->is_today;
echo $time ->tomorrow;
echo $time ->tomorrow->is_future
echo $time ->yesterday;
echo $time ->yesterday->is_past
echo $time ->monday;
echo $time ->sunday;
echo $time ->timestamp;
echo $time ;
$time ->timestamp += 3600 * 4 ;
echo $time ;
echo $time ->zone;
echo $time ->zone->offset;
echo $time ->zone->location;
echo $time ->zone->location->latitude;
$time ->zone = 'Asia/Tokyo' ;
echo $time ;
$time ->hour += 72 ;
echo "Rendez-vous in 72 hours: $time " ;
Empty dates are also supported:
<?php
$time = new DateTime('0000-00-00' , 'utc' );
$time = DateTime::none();
echo $time ;
echo $time ->is_empty;
echo $time ->as_date;
echo $time ->as_db;
DateTime
implements
DateTimeInterface
┗
ICanBoogie\DateTime
Namespace: ICanBoogie
See:
http://en.wikipedia.org/wiki/ISO_8601
Located at DateTime.php
Methods summary
public static
from ( mixed $source
, mixed $timezone
= null )
: ICanBoogie\DateTime
Creates a ICanBoogie\DateTime
instance from a source.
<?php
use ICanBoogie\DateTime;
DateTime::from(new \DateTime('2001-01-01 01:01:01' , new \DateTimeZone('Europe/Paris' )));
DateTime::from('2001-01-01 01:01:01' , 'Europe/Paris' );
DateTime::from('now' );
Parameters
$source
$timezone
The time zone to use to create the time. The value is ignored if the
source is an instance of \DateTime.
Returns
public static
now ( void )
: ICanBoogie\DateTime
Returns an instance with the current local time and the local time zone.
Returns an instance with the current local time and the local time zone.
Returns
public static
none ( DateTimeZone|string $timezone
= 'utc' )
: ICanBoogie\DateTime
Returns an instance representing an empty date ("0000-00-00").
Returns an instance representing an empty date ("0000-00-00").
<?php
use ICanBoogie\DateTime;
$d = DateTime::none();
$d ->is_empty;
$d ->zone->name;
$d = DateTime::none('Asia/Tokyo' );
$d ->is_empty;
$d ->zone->name;
Parameters
$timezone
The time zone in which the empty date is created.
Defaults to "UTC".
Returns
public
__construct ( string $time
= 'now' , DateTimeZone|string|null $timezone
= null )
If the time zone is specified as a string a \DateTimeZone instance is created and
used instead.
If the time zone is specified as a string a \DateTimeZone instance is created and
used instead.
<?php
use ICanBoogie\DateTime;
new DateTime('2001-01-01 01:01:01' , new \DateTimeZone('Europe/Paris' )));
new DateTime('2001-01-01 01:01:01' , 'Europe/Paris' );
new DateTime;
Parameters
$time
Defaults to "now".
$timezone
Overrides
DateTime::__construct
public
__get ( $property
)
protected
get_monday ( void )
: ICanBoogie\DateTime
Returns Monday of the week.
Returns Monday of the week.
Returns
protected
get_tuesday ( void )
: ICanBoogie\DateTime
Returns Tuesday of the week.
Returns Tuesday of the week.
Returns
protected
get_wednesday ( void )
: ICanBoogie\DateTime
Returns Wednesday of the week.
Returns Wednesday of the week.
Returns
protected
get_thursday ( void )
: ICanBoogie\DateTime
Returns Thursday of the week.
Returns Thursday of the week.
Returns
protected
get_friday ( void )
: ICanBoogie\DateTime
Returns Friday of the week.
Returns Friday of the week.
Returns
protected
get_saturday ( void )
: ICanBoogie\DateTime
Returns Saturday of the week.
Returns Saturday of the week.
Returns
protected
get_sunday ( void )
: ICanBoogie\DateTime
Returns Sunday of the week.
Returns Sunday of the week.
Returns
public
__set ( $property
, $value
)
Sets the $year, $month, $day, $hour, $minute,
$second, $timestamp and $zone properties.
Sets the $year, $month, $day, $hour, $minute,
$second, $timestamp and $zone properties.
Throws
PropertyNotWritable in attempt to set a read-only property.
PropertyNotDefined in attempt to set an unsupported property.
public
__call ( $method
, $arguments
)
Handles the format_as_*
methods.
Handles the format_as_*
methods.
If the format is RFC822 or RFC1123 and the time zone is equivalent to GMT,
the offset +0000
is replaced by GMT
according to the specs.
If the format is ISO8601 and the time zone is equivalent to UTC, the offset +0000
is replaced by Z
according to the specs.
Throws
BadMethodCallException in attempt to call an unsupported method.
public
__toString ( void )
: The
Returns the datetime formated as ISO8601.
Returns the datetime formated as ISO8601.
Returns
The
instance rendered as an ISO8601 string, or an empty string if the
datetime is empty.
public
setTimezone ( $timezone
)
The timezone can be specified as a string.
The timezone can be specified as a string.
If the timezone is local
the timezone returned by date_default_timezone_get() is
used instead.
Overrides
DateTime::setTimezone
public
change ( array $options
, boolean $cascade
= false )
Modifies the properties of the instance occording to the options.
Modifies the properties of the instance occording to the options.
The following properties can be updated: $year, $month, $day,
$hour, $minute and $second.
Note: Values exceeding ranges are added to their parent values.
<?php
use ICanBoogie\DateTime;
$time = new DateTime('now' );
$time ->change(array ('year' => 2000 , 'second' => 0 ));
Parameters
$options
$cascade
If true
, time options (hour
, minute
, second
) reset
cascadingly, so if only the hour is passed, then minute and second is set to 0. If the hour
and minute is passed, then second is set to 0.
Methods inherited from DateTime
__set_state()
,
__wakeup()
,
add()
,
createFromFormat()
,
diff()
,
getLastErrors()
,
getOffset()
,
getTimestamp()
,
getTimezone()
,
modify()
,
setDate()
,
setISODate()
,
setTime()
,
setTimestamp()
,
sub()
Magic methods summary
Constants summary
COOKIE
: string
We redefine the constant to make sure that the cookie uses a valid pattern.
We redefine the constant to make sure that the cookie uses a valid pattern.
See
http://grokbase.com/t/php/php-bugs/111xynxd6m/php-bug-bug-53879-new-datetime-createfromformat-fails-to-parse-cookie-expiration-date
'l, d-M-Y H:i:s T'
DB
: string
DB (example: 2013-02-03 20:59:03)
DB (example: 2013-02-03 20:59:03)
'Y-m-d H:i:s'
NUMBER
: string
Number (example: 20130203205903)
Number (example: 20130203205903)
'YmdHis'
DATE
: string
Date (example: 2013-02-03)
Date (example: 2013-02-03)
'Y-m-d'
Constants inherited from DateTime
ATOM
,
COOKIE
,
ISO8601
,
RFC1036
,
RFC1123
,
RFC2822
,
RFC3339
,
RFC3339_EXTENDED
,
RFC822
,
RFC850
,
RSS
,
W3C
Properties summary
Magic properties
public
$timestamp
: integer
public read-only
$quarter
: integer
public read-only
$week
: integer
public read-only
$weekday
: integer
public read-only
$year_day
: integer
public read-only
$is_monday
: boolean
true
if the instance represents Monday.
public read-only
$is_tuesday
: boolean
true
if the instance represents Tuesday.
public read-only
$is_wednesday
: boolean
true
if the instance represents Wednesday.
public read-only
$is_thursday
: boolean
true
if the instance represents Thursday.
public read-only
$is_friday
: boolean
true
if the instance represents Friday.
public read-only
$is_saturday
: boolean
true
if the instance represents Satruday.
public read-only
$is_sunday
: boolean
true
if the instance represents Sunday.
public read-only
$is_today
: boolean
true
if the instance is today.
public read-only
$is_past
: boolean
true
if the instance lies in the past.
public read-only
$is_future
: boolean
true
if the instance lies in the future.
public read-only
$is_empty
: boolean
true
if the instance represents an empty date such as "0000-00-00" or "0000-00-00 00:00:00".
public read-only
$tomorrow
: ICanBoogie\DateTime
A new instance representing the next day. Time is reseted to 00:00:00.
public read-only
$yesterday
: ICanBoogie\DateTime
A new instance representing the previous day. Time is reseted to 00:00:00.
public read-only
$monday
: ICanBoogie\DateTime
A new instance representing Monday of the week. Time is reseted to 00:00:00.
public read-only
$tuesday
: ICanBoogie\DateTime
A new instance representing Tuesday of the week. Time is reseted to 00:00:00.
public read-only
$wednesday
: ICanBoogie\DateTime
A new instance representing Wednesday of the week. Time is reseted to 00:00:00.
public read-only
$thursday
: ICanBoogie\DateTime
A new instance representing Thursday of the week. Time is reseted to 00:00:00.
public read-only
$friday
: ICanBoogie\DateTime
A new instance representing Friday of the week. Time is reseted to 00:00:00.
public read-only
$saturday
: ICanBoogie\DateTime
A new instance representing Saturday of the week. Time is reseted to 00:00:00.
public read-only
$sunday
: ICanBoogie\DateTime
A new instance representing Sunday of the week. Time is reseted to 00:00:00.
public read-only
$as_atom
: string
The instance formatted according to ATOM.
public read-only
$as_cookie
: string
public read-only
$as_iso8601
: string
The instance formatted according to ISO8601.
public read-only
$as_rfc822
: string
The instance formatted according to RFC822.
public read-only
$as_rfc850
: string
The instance formatted according to RFC850.
public read-only
$as_rfc1036
: string
The instance formatted according to RFC1036.
public read-only
$as_rfc1123
: string
The instance formatted according to RFC1123.
public read-only
$as_rfc2822
: string
The instance formatted according to RFC2822.
public read-only
$as_rfc3339
: string
The instance formatted according to RFC3339.
public read-only
$as_rss
: string
The instance formatted according to RSS.
public read-only
$as_w3c
: string
The instance formatted according to W3C.
public read-only
$as_db
: string
public read-only
$as_number
: string
public read-only
$as_date
: string
public read-only
$as_time
: string
public read-only
$is_utc
: boolean
true
if the instance is in the UTC timezone.
public read-only
$is_local
: boolean
true
if the instance is in the local timezone.
public read-only
$is_dst
: boolean
true
if time occurs during Daylight Saving Time in its time zone.