本文整理汇总了PHP中DateTimeObj::dateFormatToStrftime方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeObj::dateFormatToStrftime方法的具体用法?PHP DateTimeObj::dateFormatToStrftime怎么用?PHP DateTimeObj::dateFormatToStrftime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DateTimeObj
的用法示例。
在下文中一共展示了DateTimeObj::dateFormatToStrftime方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: format
/**
* Formats the given date and time `$string` based on the given `$format`.
* Optionally the result will be localized and respect a timezone differing
* from the system default. The default output is ISO 8601.
*
* @since Symphony 2.2.1
* @param string $string (optional)
* A string containing date and time, defaults to the current date and time
* @param string $format (optional)
* A valid PHP date format, defaults to ISO 8601
* @param boolean $localize (optional)
* Localizes the output, if true, defaults to true
* @param string $timezone (optional)
* The timezone associated with the timestamp
* @return string
* The formatted date
*/
public static function format($string = 'now', $format = DateTime::ISO8601, $localize = true, $timezone = null)
{
// Current date and time
if ($string == 'now' || empty($string)) {
$date = new DateTime();
} elseif (is_numeric($string)) {
$date = new Datetime(date(DateTime::ISO8601, $string));
} else {
// Standardize date
// Convert date string to English
$string = Lang::standardizeDate($string);
// PHP 5.3: Apply Symphony date format using `createFromFormat`
if (method_exists('DateTime', 'createFromFormat')) {
$date = DateTime::createFromFormat(__SYM_DATETIME_FORMAT__, $string);
if ($date === false) {
$date = DateTime::createFromFormat(__SYM_DATE_FORMAT__, $string);
}
} else {
$date = strptime($string, DateTimeObj::dateFormatToStrftime(__SYM_DATETIME_FORMAT__));
if ($date === false) {
$date = DateTimeObj::dateFormatToStrftime(__SYM_DATE_FORMAT__, $string);
}
if (is_array($date)) {
$date = date(DateTime::ISO8601, mktime($date['tm_hour'], $date['tm_min'], $date['tm_sec'], $date['tm_mon'] + 1, $date['tm_mday'], 1900 + $date['tm_year']));
$date = new DateTime($date);
}
}
// Handle non-standard dates (ie. relative dates, tomorrow etc.)
if ($date === false) {
$date = new DateTime($string);
}
}
// Timezone
if ($timezone !== null) {
$date->setTimezone(new DateTimeZone($timezone));
}
// Format date
$date = $date->format($format);
// Localize date
// Convert date string from English back to the activated Language
if ($localize === true) {
$date = Lang::localizeDate($date);
}
// Return custom formatted date, use ISO 8601 date by default
return $date;
}