Format a DateTime using ICU dateformat pattern.

@param \DateTime $dateTime A DateTime object to be used to generate the formatted value

@return string The formatted value
553892
public function format(\DateTime $dateTime)
    {
        $formatted = preg_replace_callback($this->regExp, function ($matches) use ($dateTime) {
            return $this->formatReplace($matches[0], $dateTime);
        }, $this->pattern);

        return $formatted;
    }
1064420
public function transform($dateTime)
    {
        if (null === $dateTime) {
            return '';
        }

        if (!$dateTime instanceof \DateTimeInterface) {
            throw new TransformationFailedException('Expected a \DateTimeInterface.');
        }

        if ($this->inputTimezone !== $this->outputTimezone) {
            if (!$dateTime instanceof \DateTimeImmutable) {
                $dateTime = clone $dateTime;
            }

            $dateTime = $dateTime->setTimezone(new \DateTimeZone($this->outputTimezone));
        }

        return preg_replace('/\+00:00$/', 'Z', $dateTime->format('c'));
    }
141872
public static function toHttpDate(\DateTime $dateTime)
        {
            // We need to clone it, as we don't want to affect the existing
            // DateTime.
            $dateTime = clone $dateTime;
            $dateTime->setTimeZone(new \DateTimeZone('GMT'));
            return $dateTime->format('D, d M Y H:i:s \G\M\T');
        }
1075073
protected function formatDateTime(\DateTime $date = null, $format = null)
    {
        return $date && $format ?
            $date->format($format) :
            $date
        ;
    }
188018
public static function getDateSQLToForm($datetime)
    { 
        //YYYY-mm-dd
        $t = $this->splitDate($datetime, false);

        return $t['date'] . '/' . $t['month'] . '/' . $t['year'];
    }
442891
public function formatDateTimeUtc(\DateTime $date = null)
    {
        if (null === $date) {
            return null;
        }

        $date->setTimezone(new \DateTimeZone('UTC'));

        return $date->format("Y-m-d\TH:i:s\Z");
    }
1163434
public function transform($dateTime)
    {
        if (null === $dateTime) {
            return '';
        }

        if (!$dateTime instanceof \DateTime) {
            throw new TransformationFailedException('Expected a \DateTime.');
        }

        // convert time to UTC before passing it to the formatter
        $dateTime = clone $dateTime;
        $value = $this->getIntlDateFormatter()->format((int) $dateTime->format('U'));

        return $value;
    }
1292067
public function transform($dateTime)
    {
        if (null === $dateTime) {
            return array_intersect_key([
                'year' => '',
                'month' => '',
                'day' => '',
                'hour' => '',
                'minute' => '',
                'second' => '',
            ], array_flip($this->fields));
        }

        if (!$dateTime instanceof \DateTimeInterface) {
            throw new TransformationFailedException('Expected a \DateTimeInterface.');
        }

        if ($this->inputTimezone !== $this->outputTimezone) {
            if (!$dateTime instanceof \DateTimeImmutable) {
                $dateTime = clone $dateTime;
            }

            $dateTime = $dateTime->setTimezone(new \DateTimeZone($this->outputTimezone));
        }

        $result = array_intersect_key([
            'year' => $dateTime->format('Y'),
            'month' => $dateTime->format('m'),
            'day' => $dateTime->format('d'),
            'hour' => $dateTime->format('H'),
            'minute' => $dateTime->format('i'),
            'second' => $dateTime->format('s'),
        ], array_flip($this->fields));

        if (!$this->pad) {
            foreach ($result as &$entry) {
                // remove leading zeros
                $entry = (string) (int) $entry;
            }
            // unset reference to keep scope clear
            unset($entry);
        }

        return $result;
    }
682656
public static function FromDateTime( \DateTime $dt ) : DateTime
   {

      if ( $dt instanceof DateTime )
      {
         return clone $dt;
      }

      return new DateTime( $dt->format('Y-m-d H:i:s.u'), $dt->getTimezone() );

   }
1370047
public static function unixTime($dateTime)
    {
        $t = $this->splitDate($dateTime, 'int');

        return mktime($t['hour'], $t['minute'], $t['second'], $t['month'], $t['date'], $t['year']);
    }
1108037
public function writeDateTime(DateTime $dateTime)
    {
        try {
            $timeStamp = $dateTime->getTimestamp();
            $this->getStream()->write(pack('l', $timeStamp));
        } catch (StreamException $e) {
            $this->handleStreamException($e, BinaryStreamAccessException::DATETIME, false);
        }
    }
957168
public function dateTimeString(string $time): string
    {
        return date($this->dateTimeFormat, ctype_digit($time) ? $time : strtotime($time));
    }
1266273
protected function addDateTime( CalendarDateTime $dateTime ) {
    	$this->addLine('BEGIN:VEVENT');
		$this->addLine('UID:' . $this->getUID($dateTime) );
		$this->addLine('DTSTAMP;TZID=' . Calendar::config()->timezone . ':' . $this->getFormatedDateTime());
		$this->addLine('DTSTART;TZID=' . Calendar::config()->timezone . ':' . $this->getFormatedDateTime($dateTime->dbObject('StartDate'), $dateTime->dbObject('StartTime')));
		$this->addLine('DTEND;TZID='   . Calendar::config()->timezone . ':' . $this->getFormatedDateTime($dateTime->dbObject('EndDate'), $dateTime->dbObject('EndTime')));
		$this->addLine('URL:' . Director::absoluteURL($dateTime->ICSLink()));
		$this->addLine('SUMMARY:CHARSET=UTF-8:' . $dateTime->Event()->Title);
		$this->addLine('END:VEVENT');
    }
1167159
public static function ToTimestamp($DateTime = '') {
      if (($TestTime = strtotime($DateTime)) !== FALSE) {
         return $TestTime;
      } elseif (preg_match('/^(\d{4})-(\d{1,2})-(\d{1,2})(?:\s{1}(\d{1,2}):(\d{1,2})(?::(\d{1,2}))?)?$/', $DateTime, $Matches)) {
         $Year = $Matches[1];
         $Month = $Matches[2];
         $Day = $Matches[3];
         $Hour = ArrayValue(4, $Matches, 0);
         $Minute = ArrayValue(5, $Matches, 0);
         $Second = ArrayValue(6, $Matches, 0);
         return mktime($Hour, $Minute, $Second, $Month, $Day, $Year);
      } elseif (preg_match('/^(\d{4})-(\d{1,2})-(\d{1,2})$/', $DateTime, $Matches)) {
         $Year = $Matches[1];
         $Month = $Matches[2];
         $Day = $Matches[3];
         return mktime(0, 0, 0, $Month, $Day, $Year);
      // } elseif ($DateTime == '') {
      //    return time();
      } else {
         return FALSE;
      }
   }
484014
public function getDate(\DateTimeInterface $dateTime)
    {
        $date = new Date($dateTime);
        $this->loadDay($date);

        return $date;
    }
1101973
public function getISO8601ForUser(\DateTime $datetime = null)
    {
        if ($datetime) {
            $datetime->setTimezone($this->userManager->getTimezone());
            return $datetime->format(\DateTime::ISO8601);
        }

        return null;
    }
1120273
public function getDateString(DateTime $time)
	{
		if ($this->getOption('type') === 'date')
		{
			return $time->format('Y-m-d');
		}
		else if ($this->getOption('type') === 'datetime')
		{
			return $time->format('Y-m-d H:i:s');
		}
		else
		{
			return $time->format('H:i:s');
		}
	}