DateTimeImmutable::setISODate()函数是PHP中的内置函数,用于将ISO(国际标准化组织)日期设置为创建的DateTimeImmutable对象。此功能使用星期和日期偏移量而不是特定日期,根据ISO 8601标准设置日期。
用法:
DateTimeImmutable DateTimeImmutable::setISODate( int year, int week, int day) )
参数:此函数接受上述和以下所述的三个参数:
year:此参数以整数格式保存年份值。
week:此参数以整数格式保存星期值。
day:此参数以整数格式保存日期值。
返回值:此函数返回一个新日期。
以下示例程序旨在说明PHP中的DateTimeImmutable::setISODate()函数:
示例1:
// PHP program to illustrate DateTimeImmutable::setISODate()
// function
// Creating a new DateTimeImmutable() object
$datetimeImmutable = new DateTimeImmutable();
// Initialising year, week and day
$Year = '2019';
$Week = '10';
$Day = '03';
// Calling the DateTimeImmutable::setISODate() function
$a = $datetimeImmutable->setISODate($Year, $Week, $Day);
// Getting a new set of date in the
// format of 'Y-m-d'
echo $a->format('Y-m-d');
?>
输出:
2019-03-06
示例2:
// PHP program to illustrate DateTimeImmutable::setISODate()
// function
// Creating a new DateTimeImmutable() object
$datetimeImmutable = new DateTimeImmutable();
// Calling the setISODate() function
// with parameters like years of 2019,
// week of 9 and day of 3
$a = $datetimeImmutable->setISODate(2019, 9, 03);
// Getting a new set of date in the
// format of 'Y-m-d'
echo $a->format('Y-m-d');
?>
输出:
2019-02-27