Created
August 1, 2015 22:09
-
-
Save mattisbusycom/0019d3b632a42b54ee00 to your computer and use it in GitHub Desktop.
dates in php with Carbon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$dt = Carbon::parse('2012-9-5 23:26:11.123789'); | |
// These getters specifically return integers, ie intval() | |
var_dump($dt->year); // int(2012) | |
var_dump($dt->month); // int(9) | |
var_dump($dt->day); // int(5) | |
var_dump($dt->hour); // int(23) | |
var_dump($dt->minute); // int(26) | |
var_dump($dt->second); // int(11) | |
var_dump($dt->micro); // int(123789) | |
var_dump($dt->dayOfWeek); // int(3) | |
var_dump($dt->dayOfYear); // int(248) | |
var_dump($dt->weekOfMonth); // int(1) | |
var_dump($dt->weekOfYear); // int(36) | |
var_dump($dt->daysInMonth); // int(30) | |
var_dump($dt->timestamp); // int(1346901971) | |
var_dump(Carbon::createFromDate(1975, 5, 21)->age); // int(39) calculated vs now in th | |
e same tz | |
var_dump($dt->quarter); // int(3) | |
// Returns an int of seconds difference from UTC (+/- sign included) | |
var_dump(Carbon::createFromTimestampUTC(0)->offset); // int(0) | |
var_dump(Carbon::createFromTimestamp(0)->offset); // int(-18000) | |
// Returns an int of hours difference from UTC (+/- sign included) | |
var_dump(Carbon::createFromTimestamp(0)->offsetHours); // int(-5) | |
// Indicates if day light savings time is on | |
var_dump(Carbon::createFromDate(2012, 1, 1)->dst); // bool(false) | |
var_dump(Carbon::createFromDate(2012, 9, 1)->dst); // bool(true) | |
// Indicates if the instance is in the same timezone as the local timezone | |
var_dump(Carbon::now()->local); // bool(true) | |
var_dump(Carbon::now('America/Vancouver')->local); // bool(false) | |
// Indicates if the instance is in the UTC timezone | |
var_dump(Carbon::now()->utc); // bool(false) | |
var_dump(Carbon::now('Europe/London')->utc); // bool(false) | |
var_dump(Carbon::createFromTimestampUTC(0)->utc); // bool(true) | |
// Gets the DateTimeZone instance | |
echo get_class(Carbon::now()->timezone); // DateTimeZone | |
echo get_class(Carbon::now()->tz); // DateTimeZone |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment