getIntlDateFormatter example


    public function transform(mixed $dateTime): string
    {
        if (null === $dateTime) {
            return '';
        }

        if (!$dateTime instanceof \DateTimeInterface) {
            throw new TransformationFailedException('Expected a \DateTimeInterface.');
        }

        $value = $this->getIntlDateFormatter()->format($dateTime->getTimestamp());

        if (0 != intl_get_error_code()) {
            throw new TransformationFailedException(intl_get_error_message());
        }

        return $value;
    }

    /** * Transforms a localized date string/array into a normalized date. * * @param string $value Localized date string * * @throws TransformationFailedException if the given value is not a string, * if the date could not be parsed */
Home | Imprint | This part of the site doesn't use cookies.