date_timestamp_get()

1. 定义

该函数获取指定时间对象的UNIX时间戳。

2. 语法

public DateTime::getTimestamp ( void ) : int public DateTimeImmutable::getTimestamp ( void ) : int public DateTimeInterface::getTimestamp ( void ) : int

date_timestamp_get ( DateTimeInterface $object ) : int

3. 参数说明

参数 可选性 数据类型 描述
$object 必需 DateTime 日期时间对象

4. 示例

<?php

// date_timestamp_get()
// 获取指定日期时间对象的UNIX时间戳

// 面向对象式
$date = new DateTime('2019-08-31 18:00:00');
$res = $date->getTimestamp();
var_dump($res);// 输出:int(1567245600)

// 面向过程式
$date = date_create('2019-08-31 18:00:00');
$res = date_timestamp_get($date);
var_dump($res);// 输出:int(1567245600)

5. 延展阅读