Skip to content

Latest commit

 

History

History
25 lines (20 loc) · 489 Bytes

DateTimeFieldNormalizer.md

File metadata and controls

25 lines (20 loc) · 489 Bytes

DateTimeFieldNormalizer

<?php

use Chubbyphp\Serialization\Accessor\PropertyAccessor;
use Chubbyphp\Serialization\Normalizer\DateTimeFieldNormalizer;
use Chubbyphp\Serialization\Normalizer\FieldNormalizer;
use MyProject\Model\Model;

$model = new Model;
$context = ...;

$fieldNormalizer = new DateTimeFieldNormalizer(
    new PropertyAccessor('at'),
    'Y-m-d H:i:s'
);

echo $fieldNormalizer->normalizeField(
    'at',
    $model,
    $context
);
// '2017-01-01 22:00:00'