PHP 8.1.28 Released!

IntlDateFormatter::parse

datefmt_parse

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

IntlDateFormatter::parse -- datefmt_parse文字列をパースしてタイムスタンプにする

説明

オブジェクト指向型

public IntlDateFormatter::parse(string $string, int &$offset = null): int|float|false

手続き型

datefmt_parse(IntlDateFormatter $formatter, string $string, int &$offset = null): int|float|false

string を時間に変換します。offset からパースを開始し、 入力値を可能な限り使用します。

パラメータ

formatter

Formatter リソース。

string

時間に変換する文字列。

offset

string のパースを開始する位置 (ゼロから数えます)。 string を処理する前にエラーが発生していない場合は offset は -1 となります。それ以外の場合はパースが終了した位置となります (そしてエラーが発生します)。 この変数には、パースが失敗した場合にその終了位置が含まれます。 offset > strlen($string) の場合、パースは即時に失敗します。

戻り値

タイムスタンプとしてパースされた値を返します。 パースできなかった場合は false を返します。

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

<?php
$fmt
= new IntlDateFormatter(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo
'First parsed output is ' . $fmt->parse('Wednesday, December 20, 1989 4:00:00 PM PT');
$fmt = new IntlDateFormatter(
'de-DE',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
?>

例2 datefmt_parse() の例

<?php
$fmt
= datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo
'First parsed output is ' . datefmt_parse($fmt, 'Wednesday, December 20, 1989 4:00:00 PM PT');
$fmt = datefmt_create(
'de-DE',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo
'Second parsed output is ' . datefmt_parse($fmt, 'Mittwoch, 20. Dezember 1989 16:00 Uhr GMT-08:00');
?>

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

First parsed output is 630201600
Second parsed output is 630201600

参考

add a note

User Contributed Notes 1 note

up
1
Anonymous
5 years ago
Please note:
* on a 32-bit system, parse() will return float if the value gets out of integer range
* while parse() parses fractional seconds with a format like 'yyyy-MM-dd HH:mm:ss.SSSSSS', it only returns an int. This is also true when the value is returned as float, msecs remain absent in the return value.
To Top