isodate php 时间转换,PHP DateTimeImmutable setISODate()用法及代码示例

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值