(PHP 5 >= 5.2.0, PHP 7)
DateTime::setTime -- date_time_set — ���� DateTime �����ʱ��
���������
$hour
, int $minute
[, int $second
= 0
[, int $microseconds
= 0
]] ) : DateTime���̻����
$object
, int $hour
, int $minute
[, int $second
= 0
[, int $microseconds
= 0
]] ) : DateTime���� DateTime �����ʱ�䡣
object
�����̻������ date_create() ���ص� DateTime ���͵Ķ��˺��������������
hour
Сʱ��
minute
���ӡ�
second
�롣
microseconds
�롣
���ر��ĵ� DateTime ���� ������ʧ��ʱ���� FALSE
.
�汾 | ˵�� |
---|---|
7.1.0 | ���� microseconds ������ |
5.3.0 | ������ֵ��NULL ��Ϊ DateTime ���͡� |
Example #1 DateTime::setTime() ����
���������
<?php
$date = new DateTime('2001-01-01');
$date->setTime(14, 55);
echo $date->format('Y-m-d H:i:s') . "\n";
$date->setTime(14, 55, 24);
echo $date->format('Y-m-d H:i:s') . "\n";
?>
���̻����
<?php
$date = date_create('2001-01-01');
date_time_set($date, 14, 55);
echo date_format($date, 'Y-m-d H:i:s') . "\n";
date_time_set($date, 14, 55, 24);
echo date_format($date, 'Y-m-d H:i:s') . "\n";
?>
�������̵���������ڣ�
2001-01-01 14:55:00 2001-01-01 14:55:24
Example #2 ������Ч��Χ�IJ��ֻ����ӵ���һ��
<?php
$date = new DateTime('2001-01-01');
$date->setTime(14, 55, 24);
echo $date->format('Y-m-d H:i:s') . "\n";
$date->setTime(14, 55, 65);
echo $date->format('Y-m-d H:i:s') . "\n";
$date->setTime(14, 65, 24);
echo $date->format('Y-m-d H:i:s') . "\n";
$date->setTime(25, 55, 24);
echo $date->format('Y-m-d H:i:s') . "\n";
?>
�������̻������
2001-01-01 14:55:24 2001-01-01 14:56:05 2001-01-01 15:05:24 2001-01-02 01:55:24