DateTimeImmutable DateTimeImmutable::setTime (int $hour, int $minute, int $second, int $microseconds)Parameters:This function takes four parameters as specified above and described below:
- $hour:this parameter is used to set hours .
- $minute:this parameter is used to set the minute time.
- $second:this parameter is used to set a second time.
- $microseconds:This parameter is used to set the time in microseconds.
// PHP illustration program DateTimeImmutable::setTime()
// function
// Create a new DateTimeImmutable()
$datetimeImmutable
=
new
DateTimeImmutable (
’2019-10-04’
);
// Initialize hour, minute and second
$Hour
=
’04’
;
$Minute
=
’10’
;
$Second
=
’40’
;
// Calling the DateTimeImmutable::setTime() function
$a
=
$datetimeImmutable
-> setTime (
$Hour
,
$Minute
,
$Second
);
// Get a new set of date and time in
// format ’ Ymd H: i: s ’
echo
$a
-> format (
’Ymd H: i: s’
);
?>
Exit:2019-10 -04 04:10:40
Program 2:
// PHP illustration program DateTimeImmutable::setTime()
// function
// Create a new DateTimeImmutable() object
$datetimeImmutable
=
new
DateTimeImmutable (
’2019-10-04’
);
// Calling the setTime() function
// with parameters such as 10 hour
// 33 minutes and 39 seconds
$a
=
$datetimeImmutable
-> setTime (10, 33, 39);
// Get a new set of date and time in
// format ’ Ymd H: i: s ’
echo
$a
-> format (
’Ymd H: i: s’
);
?>
Exit:2019-10 -04 10:33:39
Link: https: / /www.php.net/manual/en/datetimeimmutable.settime.php
Shop
Latest questions
Wiki