Formats the value as a time using the {@link locale}s date formatter.
@param mixed $value the value to be formatted
@return string the formatted result
@see timeFormat
@see CLocale::getDateFormatter()
518163
public function formatTime($value)
	{
		return $this->getLocale()->dateFormatter->formatDateTime($this->normalizeDateValue($value), null, $this->timeFormat);
	}
905433
protected function formatValue($format, $value)
    {
        switch ($format) {
            case Format::DATE:
            case Format::DATETIME:
                if ($value instanceof \DateTime) {
                    return $value->format('c');
                }
                break;

            case Format::FLOAT2:
            case Format::MONEY2:
                return floatval(sprintf("%.2f", $value));

            case Format::PCT2:
                return floatval(sprintf('%.2f', $value*100));

            case Format::PCT:
                return intval(sprintf('%d', $value*100));

            case Format::INTEGER:
            case Format::MONEY:
                return intval(sprintf("%d", $value));
        }

        return $value;
    }
1239422
protected function formatValue($value)
    {
        // If the value is a date we'll format it according to the specified
        // date format.
        if ($value instanceof DateTime || $value instanceof Carbon)
        {
            $value = $value->format($this->grammar->getDateFormat());
        }

        return $value;
    }
362098
public function toPlatformValue($value)
    {
        $datetime = $this->toDateTimeObject($value);
        $format = $this->getFormat();
        
        if (strpos($format, '%') !== false) {
            return strftime($format, $datetime->getTimestamp());
        }
        
        return $datetime->format($format);
    }
946400
protected function parseDate($value)
    {
        // Skip empty values
        if (empty($value) && !is_numeric($value)) {
            return null;
        }

        // Determine value to parse
        if (is_array($value)) {
            $source = $value; // parse array
        } elseif (is_numeric($value)) {
            $source = $value; // parse timestamp
        } else {
            // Convert US date -> iso, fix y2k, etc
            $value = $this->fixInputDate($value);
            if (is_null($value)) {
                return null;
            }
            $source = strtotime($value); // convert string to timestamp
        }
        if ($value === false) {
            return false;
        }

        // Format as iso8601
        $formatter = $this->getInternalFormatter();
        return $formatter->format($source);
    }
901516
public function formatTimeago($value)
    {
        if ($value instanceof DateTime) {
            $value = date_timestamp_get($value);

        } else if (!is_numeric($value) && is_string($value)) {
            $value = strtotime($value);
        }

        return $this->inWords((time() - $value));
    }
945929
private function createDateTime($value)
    {
        if ($value instanceof DateTime) {
            return $value;
        }
        if ($value instanceof \MongoDate) {
            $dateStr = date('Y-m-d H:i:s.'.$value->usec, $value->sec);
            return new DateTime($dateStr);
        }
        if (is_numeric($value)) {
            // Supports microseconds
            $value = (Float) $value;
            $usec = round(($value - (Integer) $value) * 1000000, 0);
            $dateStr = date('Y-m-d H:i:s.'.$usec, (Integer) $value);
            return new DateTime($dateStr);
        }
        return new DateTime((String) $value);
    }
847241
public function setDatetimeFormat($value)
    {
        if (!in_array($value, self::datetimeFormats(), true)) {
            throw new DomainException(
                sprintf(self::MSG_UNEXPECTED_DATETIME_FORMAT, implode(', ', self::datetimeFormats()))
            );
        }

        return $this->setAttribute('datetimeFormat', $value);
    }
1305362
public function convertToDate($value) {

		foreach($this -> date_formats as $format) {

			if(false !== \DateTime :: createFromFormat($format, $value)) {

				$d = new DateTime($value);
				$d -> createFromFormat($format, $value);

				if($d && $d -> format($format) == $value) {

					$d -> saveFormat($format);
					return $d;
				}
			}
		}

		return $value;
	}
221781
protected function prepareValue($value)
    {
        if ($this->hasMutator()) {
            return call_user_func($this->getMutator(), $value);
        } elseif ($value && $this->isElementOfDate() && $this->isDateCastable()) {
            $value = $this->castValueAsDateTime($value);
            if ($this instanceof Timestamp) {
                $value = $value->getTimestamp();
            }

            return $value;
        }

        if (! is_null($value)) {
            if ($this->isJsonCastable()) {
                return $this->castValueAsJson($value);
            } elseif ($this->isCommaCastable()) {
                return $this->castValueAsCommaSeparated($value);
            }
        }

        return $value;
    }
1199123
protected function normalize_date_time( $value ) {

		if ( $value === '' || $value === NULL ) {
			return $value;
		}
		if ( ! is_string( $value ) && ! is_int( $value ) && ! $value instanceof DateTime ) {
			return $value;
		}
		if ( is_int( $value ) ) {
			//timestamp
			$value = new \DateTime( '@' . $value );
		} elseif ( ! $value instanceof DateTime ) {
			$value = new \DateTime( $value );
		}

		return $value->format( $this->options[ 'format' ] );
	}
108556
private function toDateTimeObject($value)
    {
        $datetime = null;
        
        switch (true) {
            case $value instanceof \DateTime:
                $datetime = new DateTime($value->format(\DateTime::RFC3339));
                break;
            case is_numeric($value):
                $datetime = new DateTime(sprintf('@%d', $value));
                break;
            case is_string($value):
                $datetime = new DateTime($value);
                break;
        }
        
        return $datetime;
    }
28417
public function format($value, $params = null, $locale = null) {
		if (! isset($params['primary'])) {
			return $this->getFormatter($locale)->format($value);
		}
		
		if ($params['primary'] === 'day') {
			return $this->getFormatterDay($locale)->format($value);
		}
		
		if ($params['primary'] === 'time') {
			return $this->getFormatterTime($locale)->format($value);
		}
		
		return $this->getFormatter($locale)->format($value);
	}
1111294
public static function TEXTFORMAT($value, $format)
    {
        $value  = PHPExcel_Calculation_Functions::flattenSingleValue($value);
        $format = PHPExcel_Calculation_Functions::flattenSingleValue($format);

        if ((is_string($value)) && (!is_numeric($value)) && PHPExcel_Shared_Date::isDateTimeFormatCode($format)) {
            $value = PHPExcel_Calculation_DateTime::DATEVALUE($value);
        }

        return (string) PHPExcel_Style_NumberFormat::toFormattedString($value, $format);
    }
1274141
protected function normalizeDateTime($value)
    {
        try {
            if (is_int($value)) {
                //timestamp
                $value = new DateTime("@$value");
            } elseif (!$value instanceof DateTime) {
                $value = new DateTime($value);
            }
        } catch (\Exception $e) {
            throw new InvalidArgumentException('Invalid date string provided', $e->getCode(), $e);
        }

        return $value;
    }
1105914
static public function datetime($value=null, $format=null)
    {
        $value = static::toUnixtime($value);
        if (!$format) {
            $value = strftime('%Y-%m-%d %H:%M:%S', $value);
        } else {
            if (strpos($format, '%') === false) {
                $format = preg_replace('/([a-z])/i', '%\\1', $format);
            }
            $value = strftime($format, $value);
        }
        return $value;
    }
1092700
protected function getDateTime($value)
    {
        try {
            if ($this->isTestingRelativeDateTime($value)) {
                return Date::parse($value);
            }

            return new DateTime($value);
        } catch (Exception $e) {
            //
        }
    }