IntlDateFormatter::localtime
PHP Manual
PHP Manual»IntlDateFormatter»IntlDateFormatter::localtime

IntlDateFormatter::localtime

datefmt_localtime

(PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL intl >= 1.0.0)

IntlDateFormatter::localtime -- datefmt_localtime — 文字列をパースして、フィールドベースの時刻値にする

説明

オブジェクト指向型

public function IntlDateFormatter::localtime(string $string, int &$offset = null): array|false

手続き型

function datefmt_localtime(IntlDateFormatter $formatter, string $string, int &$offset = null): array|false

string を変換し、フィールドベースの時刻値 (各フィールドを含む配列) にします。offset からパースを開始し、入力文字列を可能な限り使用します。

パラメータ

formatter

IntlDateFormatter オブジェクト。

string

時間に変換する文字列。

offset

string のパースを開始する位置 (ゼロから数えます)。 呼び出し後は、パースが成功したかどうかにかかわらず、 offset にパースが終了した位置が格納されます。 offset が負の値の場合、または strlen($string) より大きい場合は、パースは即座に失敗し、 offset は変更されません。

戻り値

localtime() と同じキーを持つ、整数値の連想配列を返します。 24 時間制の時間が tm_hour に格納されます。失敗した場合に false を返します。 tm_yday は、localtime() が 0 から始まる値を返すのに対し、 ここでは 1 から始まる点に注意してください。

例

例1 datefmt_localtime() の例

<?php

$fmt = datefmt_create(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);

$arr = datefmt_localtime($fmt, 'Wednesday, December 31, 1969 at 4:00:00 PM Pacific Standard Time', $offset);

echo 'First parsed output is ';
if ($arr) {
    foreach ($arr as $key => $value) {
        echo "$key : $value , ";
    }
}

?>

例2 オブジェクト指向の例

<?php

$fmt = new IntlDateFormatter(
    'en_US',
    IntlDateFormatter::FULL,
    IntlDateFormatter::FULL,
    'America/Los_Angeles',
    IntlDateFormatter::GREGORIAN
);

$arr = $fmt->localtime('Wednesday, December 31, 1969 at 4:00:00 PM Pacific Standard Time', $offset);

echo 'First parsed output is ';
if ($arr) {
    foreach ($arr as $key => $value) {
        echo "$key : $value , ";
    }
}

?>

上の例の出力は以下となります。

First parsed output is tm_sec : 0 , tm_min : 0 , tm_hour : 16 , tm_year : 69 ,
tm_mday : 31 , tm_wday : 3 , tm_yday : 365 , tm_mon : 11 , tm_isdst : 0 ,

参考

To Top