MongoDate::toDateTime

(PECL mongo >= 1.6.0)

MongoDate::toDateTimeReturns a DateTime object representing this date

Descrição

public MongoDate::toDateTime ( void ) : DateTime

Returns the DateTime representation of this date. The returned DateTime will use the UTC time zone.

Parâmetros

Esta função não possui parâmetros.

Valor Retornado

This date as a DateTime object.

Exemplos

Exemplo #1 MongoDate::toDateTime() example

This example demonstrates creating a DateTime object from a MongoDate object.

<?php
$d 
= new MongoDate(strtotime("2014-11-18 11:01:25"));
var_dump$d->toDateTime() );
?>

O exemplo acima irá imprimir algo similar à:

class DateTime#2 (3) {
  public $date =>
  string(26) "2014-11-18 11:01:25.000000"
  public $timezone_type =>
  int(1)
  public $timezone =>
  string(6) "+00:00"
}
add a note add a note

User Contributed Notes 1 note

up
0
Anonymous
6 years ago
method is buggy on windows version of php

instead use
date('Y/m/d', $MongoDate->sec);

or

new DateTime("@" .  $MongoDate->sec);
To Top