函数集|u

date_date_set()函数是PHP中的一个内置函数,用于设置新日期。此函数有四个参数 $object,$year,$month 美元一天 成功时返回DateTime对象,失败时返回false。这个 date_date_set() 函数是的别名 DateTime::setDate() 作用

null

语法:

date_date_set( $object, $year, $month, $day )

参数: 该函数接受上述四个参数,如下所述:

  • $object: 它是一个强制参数,用于指定date_create()函数返回的DateTime对象。
  • 美元年: 它是一个强制参数,用于指定日期的年份。
  • 每月美元: 它是一个强制参数,用于指定日期的月份。
  • $day: 它是一个强制参数,用于指定日期。

返回值: 此函数在成功时返回新的DateTime对象,在失败时返回FALSE。

下面的程序演示了PHP中的date_date_set()函数。

项目1: 打印日期时间的程序样式。

<?php
// Date_create() returns a new DateTime object.
$date = date_create();
// date_date_set() function
date_date_set( $date , 2018, 8, 31);
// Print the date in a format
echo date_format( $date , "Y/m/d" );
?>


输出:

2018/08/31

项目2: 打印日期时间的面向对象样式。

<?php
// Declare DateTime object.
$date = new DateTime();
// date_date_set() function
$date ->setDate(2018, 8, 31);
// Print the date in a format
echo $date ->format( 'Y/m/d' );
?>


输出:

2018/08/31

相关文章:

参考: http://php.net/manual/en/function.date-date-set.php

© 版权声明
THE END
喜欢就支持一下吧
点赞15 分享