array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'pt_BR', ), 'this' => array ( 0 => 'datetime.setmicrosecond.php', 1 => 'DateTime::setMicrosecond', 2 => 'Sets microsecond part of the time', ), 'up' => array ( 0 => 'class.datetime.php', 1 => 'DateTime', ), 'prev' => array ( 0 => 'datetime.setisodate.php', 1 => 'DateTime::setISODate', ), 'next' => array ( 0 => 'datetime.settime.php', 1 => 'DateTime::setTime', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/datetime/datetime/setmicrosecond.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>
(PHP 8 >= 8.4.0)
DateTime::setMicrosecond — Sets microsecond part of the time
Sets microsecond part of the time.
Like DateTimeImmutable::setMicrosecond() but works with DateTime.
microsecond0 to 999999).
Retorna o objeto DateTime modificado para encadeamento de métodos.
If the microsecond is outside the range [0, 999999],
a DateRangeError is thrown.
Exemplo #1 DateTime::setMicrosecond() example
<?php
$date = DateTime::createFromTimestamp(123.456789);
echo $date->format('Y-m-d H:i:s.u') . PHP_EOL;
$date->setMicrosecond(987654);
echo $date->format('Y-m-d H:i:s.u') . PHP_EOL;
?>O exemplo acima produzirá:
1970-01-01 00:02:03.456789 1970-01-01 00:02:03.987654