DateTimeImmutable::modify

(PHP 5 >= 5.5.0, PHP 7, PHP 8)

DateTimeImmutable::modifyタイムスタンプを変更した新しいオブジェクトを作る

説明

public DateTimeImmutable::modify(string $modifier): DateTimeImmutable|false

タイムスタンプを変更した新しい DateTimeImmutable オブジェクトを作ります。 元のオブジェクトは変更されません。

パラメータ

object

手続き型のみ: date_create() が返す DateTime オブジェクト。 この関数は、このオブジェクトを変更します。

modifier

日付/時刻 文字列。有効な書式については 日付と時刻の書式 で説明しています。

返り値

新しく作ったオブジェクトを返します。 失敗した場合に false を返します。

add a note add a note

User Contributed Notes 1 note

up
-2
dmytro dot sokil at gmail dot com
6 years ago
To modify milliseconds and microseconds use next formats:

<?php
$a
= new \DateTimeImmutable('2018-01-01 00:00:00.000');
$b = $a->modify('9 msec');
var_dump($b->format('Y-m-d H:i:s.u'));
?>

Returns string(26) "2018-01-01 00:00:00.009000"

<?php
$a
= new \DateTimeImmutable('2018-01-01 00:00:00.000');
$b = $a->modify('9 usec');
var_dump($b->format('Y-m-d H:i:s.u'));
?>

Returns "2018-01-01 00:00:00.000009"
To Top