Date クラス
Date クラスは、日付を扱うヘルバー関数を集めたものです。PHP の DateTime クラスとは異なり、
Fuel Date クラスは、i18n を完全サポートしています。You can also use the Date class for timezone conversions.
forge($timestamp = null, $timezone = null)
forge メソッドは new date オブジェクトを返します。
Static |
はい |
Parameters |
Param |
Default |
Description |
$timestamp |
null
|
date オブジェクトにセットするタイムスタンプ |
$timezone |
null
|
時刻をセットするタイムゾーン |
|
Returns |
Fuel\Core\Date Object |
Example |
print_r(Date::forge(1294176140));
// Returns
Fuel\Core\Date Object
(
[timestamp:protected] => 1294176140
[timezone:protected] => UTC
)
|
time($timezone = null)
time メソッドは、与えられたタイムゾーンの現在時刻を Date オブジェクトで返します。
Static |
はい |
Parameters |
Param |
Default |
Description |
$timezone |
null
|
時刻をセットするタイムゾーン |
|
Returns |
Fuel\Core\Date Object |
Example |
print_r(Date::time());
|
display_timezone($timezone = null)
The display_timezone method allows you to globally set a timezone which can be used
by the format() method to generate output in another timezone then the system timezone.
If you don't pass a parameter, the current display_timezone is returned.
Static |
Yes |
Parameters |
Param |
Default |
Description |
$timezone |
null
|
The display timezone to be used to format timestamps in a non-system timezone. |
|
Returns |
mixed, null, or the current display timezone if no parameter is passed. |
Example |
// set the display timezone to 'America/Lima'
Date::display_timezone('America/Lima'));
|
create_from_string($input, $pattern_key = 'local')
create_from_string は、与えられた日付文字列書式から Date オブジェクトを作成します。
この関数は、i18n のため strptime()
を使用します。このメソッドは Windows ホストでは利用できないので、代わりに strtotime()
を使用し、パターンを無視します。
Static |
はい |
Parameters |
Param |
Default |
Description |
$input |
Required |
日付文字列 |
$pattern_key |
"local" |
使用するパターン (config/date.php を参照 または直接のstrptime()パターン) |
|
Returns |
Fuel\Core\Date Object |
Example |
print_r(Date::create_from_string("01/04/2011" , "us"));
// Returns
Fuel\Core\Date Object
(
[timestamp:protected] => 1322956800
[timezone:protected] => UTC
)
|
range_to_array($start, $end, $interval = '+1 Day')
range_to_array は、指定範囲の日付を date オブジェクトの配列に変換します。
Static |
Yes |
Parameters |
Param |
Default |
Description |
$start |
Required |
開始日付を Date オブジェクトまたはタイムスタンプで指定 |
$end |
Required |
終了日付を Date オブジェクトまたはタイムスタンプで指定 |
$interval |
"+1 Day" |
Date オブジェクトを作成するインターバル |
|
Returns |
array |
Example |
$start = time();
$end = $start + 604800; // Plus 1 week
print_r(Date::range_to_array($start, $end, "+2 days"));
// Returns
Array
(
[0] => Fuel\Core\Date Object
(
[timestamp:protected] => 1294181818
[timezone:protected] => UTC
)
[1] => Fuel\Core\Date Object
(
[timestamp:protected] => 1294354618
[timezone:protected] => UTC
)
[2] => Fuel\Core\Date Object
(
[timestamp:protected] => 1294527418
[timezone:protected] => UTC
)
[3] => Fuel\Core\Date Object
(
[timestamp:protected] => 1294700218
[timezone:protected] => UTC
)
)
|
days_in_month($month, $year = null)
days_in_month は、指定した年月の日数を返す。
Static |
はい |
Parameters |
Param |
Default |
Description |
$month |
Required |
月 |
$year |
null
|
年 (デフォルトは現在の年) |
|
Returns |
int |
Example |
echo Date::days_in_month(2); // 28
echo Date::days_in_month(2, 2000); // 29
|
time_ago($timestamp, $now, $period)
time_ago メソッドは、時刻の差を返します。
Static |
はい |
Parameters |
Param |
Default |
Description |
$timestamp |
Required |
UNIX タイムスタンプ |
$now |
Optional |
The UNIX timestamp to compare against. If not given or null, use the current time |
$period |
Optional |
The timespan the answer is returned in. Possible values are 'second', 'minute', 'hour', 'day', 'week', 'month', 'year' and 'decade'. if none is specified, the largest possible is returned |
|
Returns |
string |
Example |
echo Date::time_ago(strtotime("01 January 2012")); // 1 months ago (when in February 2012)
echo Date::time_ago(strtotime("12 April 1964"), strtotime("01 March 2012")); // 5 decades ago
echo Date::time_ago(strtotime("12 April 1964"), strtotime("01 March 2012"), 'year'); // 48 years ago
|
formatted メソッドはパターンキーで指定した書式の日付を返します。 The
patterns are defined in the fuel/core/config/date.php config file - you can add your own
by creating a similar file in app/config.
This method uses patterns for the strftime()
function instead of date() to allow for i18n.
If you don't pass a timezone, the timezone set on the current Date object will be used when formatting the result. By default,
this is the system timezone, unless you have altered it by calling the set_timezone() method. You can also pass
true which will cause the global display_timezone to be used.
You can use the display_timezone to globally set a timezone to convert to, for example from a user profile
setting when a user is logged in. This will allow all dates to be displayed in the users local timezone.
Static |
いいえ |
Parameters |
Param |
Default |
Description |
$pattern_key |
"local" |
パターンキー(config/date.php を参照) |
$timezone |
null |
The timezone to use when generating the formatted output |
|
Returns |
string |
Example |
// if the system time is UTC, this will return "01/04/2011 21:22"
echo Date::forge(1294176140)->format("%m/%d/%Y %H:%M");
// set the timezone to "Europe/Amsterdam" (which is GMT+1 in January), this will return "01/04/2011 22:22"
echo Date::forge(1294176140)->set_timezone('Europe/Amsterdam')->format("%m/%d/%Y %H:%M");
// set the display timezone globally to "Europe/Amsterdam"
Date::display_timezone('Europe/Amsterdam');
// this will return "01/04/2011 22:22" too
echo Date::forge(1294176140)->format("%m/%d/%Y %H:%M", true);
|
get_timestamp()
get_timestamp メソッドは、Date オブジェクトのタイムスタンプを返します。
Static |
いいえ |
Returns |
int |
Example |
echo Date::forge(1294176140)->get_timestamp(); // 1294176140
|
get_timezone()
get_timezone メソッドは、Date オブジェクトのタイムゾーンを返します。
Static |
いいえ |
Returns |
string |
Example |
echo Date::forge(1294176140, "Europe/London")->get_timezone(); // Europe/London
|
get_timezone_abbr($display_timezone = false)
The get_timezone_abbr method returns the abbreviated timezone for either the timezone set in the Date object, or for the display timezone.
Static |
No |
Parameters |
Param |
Default |
Description |
$display_timezone |
boolean |
if true, the global display_timezone is used instead of the timezone set on the Date object |
|
Returns |
string |
Example |
echo Date::forge(1294176140, "Europe/London")->get_timezone_abbr(); // returns "GMT"
echo Date::forge(1294176140, "Europe/Amsterdam")->get_timezone_abbr(); // returns "CET"
// set the display timezone globally to "Europe/Amsterdam"
Date::display_timezone('Europe/Amsterdam');
echo Date::forge(1294176140)->get_timezone_abbr(true); // returns "CET" too
|
set_timezone($timezone)
set_timezone メソッドは、Date オブジェクトのタイムゾーンをセットします。
Static |
いいえ |
Parameters |
Param |
Default |
Description |
$timezone |
required |
Date オブジェクトにセットするタイムゾーン |
|
Returns |
string |
Example |
echo Date::forge(1294176140)->set_timezone("America/Chicago")->get_timezone(); // America/Chicago
|