IntlDateFormatter::parse

datefmt_parse

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

IntlDateFormatter::parse -- datefmt_parseAnaliza una cadena hacia un timestamp

Descripción

Estilo orientado a objetos

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

Estilo procedimental

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

Convierte string en un valor de tiempo, comenzando en offset y leyendo tantos caracteres como sea posible.

Parámetros

formatter

El recurso de formateador IntlDateFormatter.

string

La cadena a convertir en tiempo.

offset

La posición desde la cual comenzar el análisis en el valor string. Las posiciones comienzan en 0. Si no ocurre ningún error durante el análisis de string, offset contendrá -1, y de lo contrario, contendrá la posición en la cual el análisis terminó (y el error ocurrió). Esta variable contendrá la posición de fin si el análisis falla. Si offset > strlen($string), el análisis falla inmediatamente.

Valores devueltos

El valor del timestamp analizado o false si el valor no pudo ser analizado.

Ejemplos

Ejemplo #1 Ejemplo orientado a objetos

<?php
$fmt
= new IntlDateFormatter(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo
'El primer formato analizado es ' . $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
);
?>

Ejemplo #2 Ejemplo con datefmt_parse()

<?php
$fmt
= datefmt_create(
'en_US',
IntlDateFormatter::FULL,
IntlDateFormatter::FULL,
'America/Los_Angeles',
IntlDateFormatter::GREGORIAN
);
echo
'El primer formato analizado es ' . 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
'El segundo formato analizado es ' . datefmt_parse($fmt, 'Mittwoch, 20. Dezember 1989 16:00 Uhr GMT-08:00');
?>

El ejemplo anterior mostrará :

El primer formato analizado es 630201600
El segundo formato analizado es 630201600

Ver también

add a note

User Contributed Notes 1 note

up
0
Anonymous
7 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