Class DateTime
Representation of a date and time.
<?php // Let's say that _now_ is 2013-02-03 21:03:45 in Paris use ICanBoogie\DateTime; date_default_timezone_set('EST'); // set local time zone to Eastern Standard Time $time = new DateTime('now', 'Europe/Paris'); echo $time; // 2013-02-03T21:03:45+0100 echo $time->utc; // 2013-02-03T20:03:45Z echo $time->local; // 2013-02-03T15:03:45-0500 echo $time->utc->local; // 2013-02-03T15:03:45-0500 echo $time->utc->is_utc; // true echo $time->utc->is_local; // false echo $time->local->is_utc; // false echo $time->local->is_local; // true echo $time->is_dst; // false echo $time->as_rss; // Sun, 03 Feb 2013 21:03:45 +0100 echo $time->as_db; // 2013-02-03 21:03:45 echo $time->as_time; // 21:03:45 echo $time->utc->as_time; // 20:03:45 echo $time->local->as_time; // 15:03:45 echo $time->utc->local->as_time; // 15:03:45 echo $time->quarter; // 1 echo $time->week; // 5 echo $time->day; // 3 echo $time->minute; // 3 echo $time->is_monday; // false echo $time->is_saturday; // true echo $time->is_today; // true echo $time->tomorrow; // 2013-02-04T00:00:00+0100 echo $time->tomorrow->is_future // true echo $time->yesterday; // 2013-02-02T00:00:00+0100 echo $time->yesterday->is_past // true echo $time->monday; // 2013-01-28T00:00:00+0100 echo $time->sunday; // 2013-02-03T00:00:00+0100 echo $time->timestamp; // 1359921825 echo $time; // 2013-02-03T21:03:45+0100 $time->timestamp += 3600 * 4; echo $time; // 2013-02-04T01:03:45+0100 echo $time->zone; // Europe/Paris echo $time->zone->offset; // 3600 echo $time->zone->location; // FR,48.86667,2.33333 echo $time->zone->location->latitude; // 48.86667 $time->zone = 'Asia/Tokyo'; echo $time; // 2013-02-04T09:03:45+0900 $time->hour += 72; echo "Rendez-vous in 72 hours: $time"; // Rendez-vous in 72 hours: 2013-02-07T05:03:45+0900
Empty dates are also supported:
<?php $time = new DateTime('0000-00-00', 'utc'); // or $time = DateTime::none(); echo $time; // -0001-11-30T00:00:00Z echo $time->is_empty; // true echo $time->as_date; // 0000-00-00 echo $time->as_db; // 0000-00-00 00:00:00
- DateTime
- ICanBoogie\DateTime
Direct known subclasses
See: http://en.wikipedia.org/wiki/ISO_8601
Located at vendor/icanboogie/datetime/lib/datetime.php
Methods summary
public static
|
#
from( mixed $source, mixed $timezone = null )
Creates a |
public static
|
|
public static
|
#
none(
Returns an instance representing an empty date ("0000-00-00"). |
public
|
#
__construct( string $time = 'now',
If the time zone is specified as a string a |
public
|
|
protected
|
|
protected
|
|
protected
|
|
protected
|
|
protected
|
|
protected
|
|
protected
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
|
public
|
#
format( mixed $format )
If the instance represents an empty date and the format is |
Methods inherited from DateTime
__set_state()
,
__wakeup()
,
add()
,
createFromFormat()
,
diff()
,
getLastErrors()
,
getOffset()
,
getTimestamp()
,
getTimezone()
,
modify()
,
setDate()
,
setISODate()
,
setTime()
,
setTimestamp()
,
sub()
Magic methods summary
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
|
public
string
|
Constants summary
string |
DB
|
'Y-m-d H:i:s' |
#
DB (example: 2013-02-03 20:59:03) |
string |
NUMBER
|
'YmdHis' |
#
Number (example: 20130203205903) |
string |
DATE
|
'Y-m-d' |
#
Date (example: 2013-02-03) |
string |
TIME
|
'H:i:s' |
#
Time (example: 20:59:03) |
Constants inherited from DateTime
ATOM
,
COOKIE
,
ISO8601
,
RFC1036
,
RFC1123
,
RFC2822
,
RFC3339
,
RFC822
,
RFC850
,
RSS
,
W3C
Properties summary
Magic properties
public
integer
|
$timestamp |
|
#
Unix timestamp. |
public
integer
|
$day |
|
#
Day of the month. |
public
integer
|
$hour |
|
#
Hour of the day. |
public
integer
|
$minute |
|
#
Minute of the hour. |
public
integer
|
$month |
|
#
Month of the year. |
public
integer
|
$second |
|
#
Second of the minute. |
public
integer
|
$year |
|
#
Year. |
public
|
$zone |
|
#
The timezone of the instance. |
public read-only
integer
|
$quarter |
|
#
Quarter of the year. |
public read-only
integer
|
$week |
|
#
Week of the year. |
public read-only
integer
|
$weekday |
|
#
Day of the week. |
public read-only
integer
|
$year_day |
|
#
Day of the year. |
public read-only
boolean
|
$is_monday |
|
#
|
public read-only
boolean
|
$is_tuesday |
|
#
|
public read-only
boolean
|
$is_wednesday |
|
#
|
public read-only
boolean
|
$is_thursday |
|
#
|
public read-only
boolean
|
$is_friday |
|
#
|
public read-only
boolean
|
$is_saturday |
|
#
|
public read-only
boolean
|
$is_sunday |
|
#
|
public read-only
boolean
|
$is_today |
|
#
|
public read-only
boolean
|
$is_past |
|
#
|
public read-only
boolean
|
$is_future |
|
#
|
public read-only
boolean
|
$is_empty |
|
#
|
public read-only
|
$tomorrow |
|
#
A new instance representing the next day. Time is reseted to 00:00:00. |
public read-only
|
$yesterday |
|
#
A new instance representing the previous day. Time is reseted to 00:00:00. |
public read-only
|
$monday |
|
#
A new instance representing Monday of the week. Time is reseted to 00:00:00. |
public read-only
|
$tuesday |
|
#
A new instance representing Tuesday of the week. Time is reseted to 00:00:00. |
public read-only
|
$wednesday |
|
#
A new instance representing Wednesday of the week. Time is reseted to 00:00:00. |
public read-only
|
$thursday |
|
#
A new instance representing Thursday of the week. Time is reseted to 00:00:00. |
public read-only
|
$friday |
|
#
A new instance representing Friday of the week. Time is reseted to 00:00:00. |
public read-only
|
$saturday |
|
#
A new instance representing Saturday of the week. Time is reseted to 00:00:00. |
public read-only
|
$sunday |
|
#
A new instance representing Sunday of the week. Time is reseted to 00:00:00. |
public read-only
string
|
$as_atom |
|
#
The instance formatted according to |
public read-only
string
|
$as_cookie |
|
#
The instance formatted according to |
public read-only
string
|
$as_iso8601 |
|
#
The instance formatted according to |
public read-only
string
|
$as_rfc822 |
|
#
The instance formatted according to |
public read-only
string
|
$as_rfc850 |
|
#
The instance formatted according to |
public read-only
string
|
$as_rfc1036 |
|
#
The instance formatted according to |
public read-only
string
|
$as_rfc1123 |
|
#
The instance formatted according to |
public read-only
string
|
$as_rfc2822 |
|
#
The instance formatted according to |
public read-only
string
|
$as_rfc3339 |
|
#
The instance formatted according to |
public read-only
string
|
$as_rss |
|
#
The instance formatted according to |
public read-only
string
|
$as_w3c |
|
#
The instance formatted according to |
public read-only
string
|
$as_db |
|
#
The instance formatted according to |
public read-only
string
|
$as_number |
|
#
The instance formatted according to |
public read-only
string
|
$as_date |
|
#
The instance formatted according to |
public read-only
string
|
$as_time |
|
#
The instance formatted according to |
public read-only
|
$utc |
|
#
A new instance in the UTC timezone. |
public read-only
|
$local |
|
#
A new instance in the local timezone. |
public read-only
boolean
|
$is_utc |
|
#
|
public read-only
boolean
|
$is_local |
|
#
|
public read-only
boolean
|
$is_dst |
|
#
|