-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8338 from kenjis/docs-time-sample-code
docs: fix Time
- Loading branch information
Showing
35 changed files
with
97 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
<?php | ||
|
||
use CodeIgniter\I18n\Time; | ||
|
||
$myTime = new Time('now', 'America/Chicago', 'en_US'); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
<?php | ||
|
||
use CodeIgniter\I18n\Time; | ||
|
||
$myTime = Time::now('America/Chicago', 'en_US'); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
<?php | ||
|
||
use CodeIgniter\I18n\Time; | ||
|
||
$myTime = Time::parse('next Tuesday', 'America/Chicago', 'en_US'); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
<?php | ||
|
||
use CodeIgniter\I18n\Time; | ||
|
||
$myTime = Time::today('America/Chicago', 'en_US'); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
<?php | ||
|
||
use CodeIgniter\I18n\Time; | ||
|
||
$myTime = Time::yesterday('America/Chicago', 'en_US'); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
<?php | ||
|
||
use CodeIgniter\I18n\Time; | ||
|
||
$myTime = Time::tomorrow('America/Chicago', 'en_US'); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
use CodeIgniter\I18n\Time; | ||
|
||
$today = Time::createFromDate(); // Uses current year, month, and day | ||
$anniversary = Time::createFromDate(2018); // Uses current month and day | ||
$date = Time::createFromDate(2018, 3, 15, 'America/Chicago', 'en_US'); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
use CodeIgniter\I18n\Time; | ||
|
||
$lunch = Time::createFromTime(11, 30); // 11:30 am today | ||
$dinner = Time::createFromTime(18, 00, 00); // 6:00 pm today | ||
$time = Time::createFromTime($hour, $minutes, $seconds, $timezone, $locale); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
<?php | ||
|
||
use CodeIgniter\I18n\Time; | ||
|
||
$time = Time::create($year, $month, $day, $hour, $minutes, $seconds, $timezone, $locale); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
<?php | ||
|
||
use CodeIgniter\I18n\Time; | ||
|
||
$time = Time::createFromFormat('j-M-Y', '15-Feb-2009', 'America/Chicago'); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
<?php | ||
|
||
use CodeIgniter\I18n\Time; | ||
|
||
$time = Time::createFromTimestamp(1501821586, 'America/Chicago', 'en_US'); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<?php | ||
|
||
use CodeIgniter\I18n\Time; | ||
|
||
$dt = new DateTime('now'); | ||
$time = Time::createFromInstance($dt, 'en_US'); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
<?php | ||
|
||
use CodeIgniter\I18n\Time; | ||
|
||
$datetime = Time::toDateTime(); |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
<?php | ||
|
||
use CodeIgniter\I18n\Time; | ||
|
||
$time = Time::parse('August 12, 2016 4:15:23pm'); | ||
|
||
echo $time->getYear(); // 2016 | ||
echo $time->getMonth(); // 8 | ||
echo $time->getDay(); // 12 | ||
echo $time->getHour(); // 16 | ||
echo $time->getMinute(); // 15 | ||
echo $time->getSecond(); // 23 | ||
// The output may vary based on locale. | ||
echo $time->getYear(); // '2016' | ||
echo $time->getMonth(); // '8' | ||
echo $time->getDay(); // '12' | ||
echo $time->getHour(); // '16' | ||
echo $time->getMinute(); // '15' | ||
echo $time->getSecond(); // '23' | ||
|
||
echo $time->year; // 2016 | ||
echo $time->month; // 8 | ||
echo $time->day; // 12 | ||
echo $time->hour; // 16 | ||
echo $time->minute; // 15 | ||
echo $time->second; // 23 | ||
echo $time->year; // '2016' | ||
echo $time->month; // '8' | ||
echo $time->day; // '12' | ||
echo $time->hour; // '16' | ||
echo $time->minute; // '15' | ||
echo $time->second; // '23' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
<?php | ||
|
||
use CodeIgniter\I18n\Time; | ||
|
||
$time = Time::parse('August 12, 2016 4:15:23pm'); | ||
|
||
echo $time->getDayOfWeek(); // 6 - but may vary based on locale's starting day of the week | ||
echo $time->getDayOfYear(); // 225 | ||
echo $time->getWeekOfMonth(); // 2 | ||
echo $time->getWeekOfYear(); // 33 | ||
echo $time->getTimestamp(); // 1471018523 - UNIX timestamp | ||
echo $time->getQuarter(); // 3 | ||
// The output may vary based on locale. | ||
echo $time->getDayOfWeek(); // '6' | ||
echo $time->getDayOfYear(); // '225' | ||
echo $time->getWeekOfMonth(); // '2' | ||
echo $time->getWeekOfYear(); // '33' | ||
echo $time->getTimestamp(); // 1471018523 - UNIX timestamp (locale independent) | ||
echo $time->getQuarter(); // '3' | ||
|
||
echo $time->dayOfWeek; // 6 | ||
echo $time->dayOfYear; // 225 | ||
echo $time->weekOfMonth; // 2 | ||
echo $time->weekOfYear; // 33 | ||
echo $time->dayOfWeek; // '6' | ||
echo $time->dayOfYear; // '225' | ||
echo $time->weekOfMonth; // '2' | ||
echo $time->weekOfYear; // '33' | ||
echo $time->timestamp; // 1471018523 | ||
echo $time->quarter; // 3 | ||
echo $time->quarter; // '3' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
use CodeIgniter\I18n\Time; | ||
|
||
$time = Time::parse('5 years ago'); | ||
|
||
echo $time->getAge(); // 5 | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<?php | ||
|
||
use CodeIgniter\I18n\Time; | ||
|
||
echo Time::createFromDate(2012, 1, 1)->getDst(); // false | ||
echo Time::createFromDate(2012, 9, 1)->dst; // true |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<?php | ||
|
||
echo Time::now()->getLocal(); // true | ||
echo Time::now('Europe/London'); // false | ||
use CodeIgniter\I18n\Time; | ||
|
||
echo Time::now()->getLocal(); // true | ||
echo Time::now('Europe/London')->local; // false |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<?php | ||
|
||
use CodeIgniter\I18n\Time; | ||
|
||
echo Time::now('America/Chicago')->getUtc(); // false | ||
echo Time::now('UTC')->utc; // true |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<?php | ||
|
||
use CodeIgniter\I18n\Time; | ||
|
||
$tz = Time::now()->getTimezone(); | ||
$tz = Time::now()->timezone; | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
<?php | ||
|
||
use CodeIgniter\I18n\Time; | ||
|
||
echo Time::now('America/Chicago')->getTimezoneName(); // America/Chicago | ||
echo Time::now('Europe/London')->timezoneName; // Europe/London |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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