DateTimeImmutable::setISODate()函數是PHP中的內置函數,用於將ISO(國際標準化組織)日期設置為創建的DateTimeImmutable對象。此函數使用星期和日期偏移量而不是特定日期,根據ISO 8601標準設置日期。
用法:
DateTimeImmutable DateTimeImmutable::setISODate( int year, int week, int day) )
參數:此函數接受上述和以下所述的三個參數:
- year:此參數以整數格式保存年份值。
- week:此參數以整數格式保存星期值。
- day:此參數以整數格式保存日期值。
返回值:此函數返回一個新日期。
以下示例程序旨在說明PHP中的DateTimeImmutable::setISODate()函數:
示例1:
<?php
// 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
// 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
參考: https://www.php.net/manual/en/datetimeimmutable.setisodate.php
相關用法
- PHP DateTimeImmutable add()用法及代碼示例
- PHP DateTimeImmutable::sub()用法及代碼示例
- PHP DateTimeImmutable setTime()用法及代碼示例
- PHP DateTimeImmutable modify()用法及代碼示例
- PHP DateTimeImmutable setTimestamp()用法及代碼示例
- PHP DateTimeImmutable::setTimezone()用法及代碼示例
- PHP DateTimeImmutable setDate()用法及代碼示例
- p5.js sin()用法及代碼示例
- p5.js red()用法及代碼示例
- p5.js tan()用法及代碼示例
- PHP pos()用法及代碼示例
- PHP key()用法及代碼示例
注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 PHP | DateTimeImmutable setISODate() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。