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); ?>

DateTime::setMicrosecond

(PHP 8 >= 8.4.0)

DateTime::setMicrosecondSets microsecond part of the time

Descrição

public function DateTime::setMicrosecond(int $microsecond): static

Sets microsecond part of the time.

Like DateTimeImmutable::setMicrosecond() but works with DateTime.

Parâmetros

microsecond
The microsecond value to set (0 to 999999).

Valor Retornado

Retorna o objeto DateTime modificado para encadeamento de métodos.

Erros/Exceções

If the microsecond is outside the range [0, 999999], a DateRangeError is thrown.

Exemplos

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

Veja Também