php settimestamp,PHP DateTimeImmutable setTimestamp()用法及代码示例

DateTimeImmutable::setTimestamp()函数是PHP中的内置函数,用于根据Unix时间戳设置日期和时间。

用法:

DateTimeImmutable DateTimeImmutable::setTimestamp( int $unixtimestamp )

参数:此函数接受单个参数$unixtimestamp,该参数用于设置表示日期的Unix时间戳。

Return Values:此函数返回DateTimeImmutable对象。

以下示例程序旨在说明PHP中的DateTimeImmutable::setTimestamp()函数:

程序1:

// PHP program to illustrate DateTimeImmutable::setTimestamp()

// function

// Creating a new DateTimeImmutable() object

$datetimeImmutable = new DateTimeImmutable();

// Initialising a unixtimestamp

$unixtimestamp = '1171564674';

// Calling the DateTimeImmutable::setTimestamp() function

$a = $datetimeImmutable->setTimestamp($unixtimestamp);

// Getting a new set of date and time in the

// format of 'U = d-m-Y H:i:s'

echo $datetimeImmutable->format('U = d-m-Y H:i:s');

?>

输出:

1570187170 = 04-10-2019 11:06:10

程序2:

// PHP program to illustrate DateTimeImmutable::setTimestamp()

// function

// Creating a new DateTimeImmutable() object

$datetimeImmutable = new DateTimeImmutable();

// Calling the DateTimeImmutable::setTimestamp() function

// with the parameter of unixtimestamp

$a = $datetimeImmutable->setTimestamp(1291564453);

// Getting a new set of date and time in the

// format of 'U = d-m-Y H:i:s'

echo $datetimeImmutable->format('U = d-m-Y H:i:s');

?>

输出:

1570187171 = 04-10-2019 11:06:11

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值