Transform a date string into a DateTime object using GMT timezone

@param $dateString a date string that can be used as a parameter for the DateTime constructor

@return \DateTime
766142
protected function dateToTimeZone($stringDate)
    {
        $date = new DateTime($stringDate);
        $date->setTimezone(new DateTimeZone($this->timeZone));
        return $date;
    }
1342045
public static function parseDateRange($dateString)
    {
        $matched = preg_match('/^([0-9]{4}-[0-9]{1,2}-[0-9]{1,2}),(([0-9]{4}-[0-9]{1,2}-[0-9]{1,2})|today|now|yesterday)$/D', trim($dateString), $regs);

        if (empty($matched)) {
            return false;
        }

        return $regs;
    }
249620
public static function TimezoneFromDateTime( $arg )
	{
		if ( $arg instanceof Undefined )
		{
			return Undefined::getValue();
		}

		if ( ! $arg instanceof DateTimeValue )
		{
			return Undefined::getValue();
		}

		/**
		 * @var DateTimeValue $dateTime
		 */
		$dateTime = $arg;

		if ( $dateTime->IsLocal )
			return Undefined::getValue();

		return $dateTime->TimezoneToInterval();
	}
125096
public static function localizeDate($string)
    {
        // Only translate dates in localized environments
        if (self::isLocalized()) {
            foreach (self::$_datetime_dictionary as $value) {
                $string = preg_replace('/\b' . $value . '\b/i', self::translate($value), $string);
            }
        }

        return $string;
    }
1033718
public static function convertDate($oldDateString, $newDateFormatString, $timezone = null) {
		$Date = new CakeTime($oldDateString, $timezone);
		return $Date->format($newDateFormatString);
	}
905267
static function makeDateTime(int $timestamp) {
        $zone = new \DateTimeZone(\date_default_timezone_get());
        return (new \DateTime('@'.$timestamp))->setTimezone($zone);
    }
966076
public static function isInTheFuture($dateString, $timezone = null) {
		$date = new CakeTime($dateString, $timezone);
		$date = $date->format('U');
		return date(FORMAT_DB_DATETIME, $date) > date(FORMAT_DB_DATETIME, time());
	}
450209
function mdatetime($time = '', $timezone = '', $datetime_format = '') {
		if ($datetime_format == '') {
			$datetime_format = $this->dateFormat . ' ' . $this->timeFormat;
		}
		if ($time == '') {
			$time = 'now';
		}
		if ($timezone == '') {
			$timezone = $this->timeZone;
		}
		$utc = new \DateTimeZone($timezone);
		$dt = new \DateTime($time, $utc);
		return $dt->format($datetime_format);
	}
972539
protected function createDateTime($timeStamp)
    {
        $date = \DateTime::createFromFormat('U', $timeStamp);

        if ($tz = $this->getTimeZone()) {
            $date->setTimezone($tz);
        }

        return $date;
    }
785079
public function datetime($datetime, $timezone = null, $format = 'M/d/Y - h:i:s A')
    {
        $datetime = new \DateTime($datetime);

        if($timezone) {

            $datetime->setTimezone(new \DateTimeZone($timezone));
        }

        return $datetime->format($format); 
    }
827279
public static Date stringToDate(String dateString) {
        if (!"".equals(dateString) && dateString != null) {
            // ISO_DATE_FORMAT = "yyyyMMdd";
            if (dateString.trim().length() == 8) {
                return stringToDate(dateString, ISO_DATE_FORMAT, LENIENT_DATE);
            } else if (dateString.trim().length() == 10) {
                // ISO_EXPANDED_DATE_FORMAT = "yyyy-MM-dd";
                return stringToDate(dateString, ISO_EXPANDED_DATE_FORMAT,
                        LENIENT_DATE);
            } else if (dateString.trim().length() == 19) {
                // DATETIME_PATTERN = "yyyy-MM-dd hh:mm:ss";
                return stringToDate(dateString, DATETIME_PATTERN, LENIENT_DATE);
            } else if (dateString.trim().length() == 11) {
                // CHINESE_EXPANDED_DATE_FORMAT = "yyyy年MM月dd日";
                return stringToDate(dateString, CHINESE_EXPANDED_DATE_FORMAT,
                        LENIENT_DATE);
            }
        }
        return null;
    }
1258339
public static function parse(string $text) : TimeZone
    {
        $text = (string) $text;

        if ($text === 'Z' || $text === 'z') {
            return TimeZoneOffset::utc();
        }

        if ($text === '') {
            throw new DateTimeParseException('The string is empty.');
        }

        if ($text[0] === '+' || $text[0] === '-') {
            return TimeZoneOffset::parse($text);
        }

        return TimeZoneRegion::parse($text);
    }
1355877
public static function parseDate($dateValue)
    {
        foreach (self::$dateFormats as $dateFormat) {
            if (false !== $date = \DateTime::createFromFormat($dateFormat, $dateValue, new \DateTimeZone('GMT'))) {
                return $date;
            }
        }

        // attempt a fallback for unusual formatting
        if (false !== $date = date_create($dateValue, new \DateTimeZone('GMT'))) {
            return $date;
        }

        throw new UnexpectedValueException(sprintf(
            'Unparseable cookie date string "%s"',
            $dateValue
        ));
    }
849851
function getDate (dateString) {
  var date = new Date(dateString);

  if (Object.prototype.toString.call(date) === '[object Date]' && !isNaN(date.getTime())) {
    return date;
  }

  //try to fix invalid date
  date = fixInvalidDate(dateString);

  //if date still isn't valid there's not more we can do..
  if (!isNaN(date.getTime())) {
    return date;
  }
}
1093700
protected function convert($data)
    {
        if ($data instanceof DateTime) {
            $data = clone $data; // don't change to original value
            return $data->setTimezone($this->timezone)->format('Y-m-d\TG:i:s\Z');
        }

        if (is_object($data) && !method_exists($data, '__toString')) {
            return null; // can't convert object to a string.
        }

        if (is_array($data)) {
            return null; // can't convert a array to a string.
        }

        if (is_bool($data)) {
            return $data ? '1' : '0'; // would otherwise be empty if converted to a string
        }

        return $data !== null ? (string)$data : null;
    }
409474
public function format($datetime, $pattern, $locale = null, $timezone = null)
    {
        $date = $this->getDatetime($datetime, $timezone);

        $formatter = self::createInstance([
            'locale' => $locale ?: $this->localeDetector->getLocale(),
            'datetype' => \IntlDateFormatter::FULL,
            'timetype' => \IntlDateFormatter::FULL,
            'timezone' => $timezone ?: $this->timezoneDetector->getTimezone(),
            'calendar' => \IntlDateFormatter::GREGORIAN,
            'pattern' => $pattern,
        ]);

        return $this->process($formatter, $date);
    }
372607
public static function formatDate($format, $timestamp)
    {
        static $datesPatterns = null;
        static $timesPatterns = null;

        if ($datesPatterns === null || $timesPatterns === null) {
            $datesPatterns = "/\b(" . implode('|', array_keys(static::$_map['date'])) . ")\b(?![^']*'(?:(?:[^']*'){2})*[^']*$)/i";
            $timesPatterns = "/\b(" . implode('|', array_keys(static::$_map['time'])) . ")\b(?![^']*'(?:(?:[^']*'){2})*[^']*$)/i";
        }

        // normalize formats
        $result = preg_replace_callback($datesPatterns, function ($matches) use ($timestamp) {
            return date(static::$_map['date'][$matches[1]], $timestamp);
        }, trim($format));

        $result = preg_replace_callback($timesPatterns, function ($matches) use ($timestamp) {
            return date(static::$_map['time'][$matches[1]], $timestamp);
        }, $result);

        return str_replace('\'', '', $result);
    }