Elastica\Util::convertDateTimeObject PHP Method

convertDateTimeObject() public static method

Converts it to the lucene format, including the appropriate TimeZone
public static convertDateTimeObject ( DateTime $dateTime, boolean $includeTimezone = true ) : string
$dateTime DateTime
$includeTimezone boolean
return string
    public static function convertDateTimeObject(\DateTime $dateTime, $includeTimezone = true)
    {
        $formatString = 'Y-m-d\\TH:i:s' . ($includeTimezone === true ? 'P' : '\\Z');
        $string = $dateTime->format($formatString);
        return $string;
    }

Usage Example

Exemplo n.º 1
0
 public function testConvertDateTimeObjectWithoutTimezone()
 {
     $dateTimeObject = new \DateTime();
     $timestamp = $dateTimeObject->getTimestamp();
     $convertedString = Util::convertDateTimeObject($dateTimeObject, false);
     $date = date('Y-m-d\\TH:i:s\\Z', $timestamp);
     $this->assertEquals($convertedString, $date);
 }