牛牛在线工具

MongoDB\BSON\UTCDateTime::__construct()

收录 8868 个 PHP 函数,含用途说明与用法示例。

MongoDB\BSON\UTCDateTime::__construct()

创建一个新的UTCDateTime对象,表示一个特定的日期和时间

函数名:MongoDB\BSON\UTCDateTime::__construct() 函数描述:该函数用于创建一个新的UTCDateTime对象,表示一个特定的日期和时间。 用法:MongoDB\BSON\UTCDateTime::__construct(int $milliseconds) 参数: $milliseconds:表示日期和时间的毫秒数,必须是一个整数。 返回值:无返回值。 示例: // 创建一个UTCDateTime对象,表示当前时间 $now = new MongoDB\BSON\UTCDateTime(time() * 1000); // 创建一个UTCDateTime对象,表示指定日期和时间 $datetime = new MongoDB\BSON\UTCDateTime(strtotime('2022-01-01') * 1000); // 输出UTCDateTime对象的日期和时间 echo $now->toDateTime()->format('Y-m-d H:i:s') . "\n"; echo $datetime->toDateTime()->format('Y-m-d H:i:s') . "\n"; 以上示例中,我们首先使用new MongoDB\BSON\UTCDateTime()创建了两个UTCDateTime对象,分别表示当前时间和指定的日期时间。然后,通过调用toDateTime()方法将UTCDateTime对象转换为PHP的DateTime对象,并使用format()方法输出日期和时间。