本文整理汇总了PHP中Zend_Date::date方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Date::date方法的具体用法?PHP Zend_Date::date怎么用?PHP Zend_Date::date使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Date
的用法示例。
在下文中一共展示了Zend_Date::date方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: date
public function date($format, $timestamp = null, $gmt = false)
{
return parent::date($format, $timestamp, $gmt);
}
示例2: isDate
/**
* Checks if the given date is a real date or datepart.
* Returns false is a expected datepart is missing or a datepart exceeds its possible border.
* But the check will only be done for the expected dateparts which are given by format.
* If no format is given the standard dateformat for the actual locale is used.
* f.e. 30.February.2007 will return false if format is 'dd.MMMM.YYYY'
*
* @param string $date Date to parse for correctness
* @param string $format OPTIONAL Format for parsing the date string
* @param string|Zend_Locale $locale OPTIONAL Locale for parsing date parts
* @return boolean True when all date parts are correct
*/
public static function isDate($date, $format = null, $locale = null)
{
if (Zend_Locale::isLocale($format)) {
$locale = $format;
$format = null;
}
if ($locale === null) {
$locale = new Zend_Locale();
$locale = $locale->toString();
}
if ($format === null) {
$format = Zend_Locale_Format::getDateFormat($locale);
} else {
if (self::$_Options['format_type'] == 'php') {
$format = Zend_Locale_Format::convertPhpToIsoFormat($format);
}
}
try {
$parsed = Zend_Locale_Format::getDate($date, array('locale' => $locale, 'date_format' => $format, 'format_type' => 'iso', 'fix_date' => false));
} catch (Zend_Locale_Exception $e) {
// date can not be parsed
return false;
}
if ((strpos($format, 'Y') !== false or strpos($format, 'y') !== false) and !isset($parsed['year'])) {
// year expected but not found
return false;
}
if (strpos($format, 'M') !== false and !isset($parsed['month'])) {
// month expected but not found
return false;
}
if (strpos($format, 'd') !== false and !isset($parsed['day'])) {
// day expected but not found
return false;
}
if ((strpos($format, 'H') !== false or strpos($format, 'h') !== false) and !isset($parsed['hour'])) {
// hour expected but not found
return false;
}
if (strpos($format, 'm') !== false and !isset($parsed['minute'])) {
// minute expected but not found
return false;
}
if (strpos($format, 's') !== false and !isset($parsed['second'])) {
// second expected but not found
return false;
}
// set not given dateparts
if (!isset($parsed['hour'])) {
$parsed['hour'] = 0;
}
if (!isset($parsed['minute'])) {
$parsed['minute'] = 0;
}
if (!isset($parsed['second'])) {
$parsed['second'] = 0;
}
if (!isset($parsed['month'])) {
$parsed['month'] = 1;
}
if (!isset($parsed['day'])) {
$parsed['day'] = 1;
}
if (!isset($parsed['year'])) {
$parsed['year'] = 1970;
}
$date = new Zend_Date($locale);
$timestamp = $date->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $parsed['month'], $parsed['day'], $parsed['year']);
if ($parsed['year'] != $date->date('Y', $timestamp)) {
// given year differs from parsed year
return false;
}
if ($parsed['month'] != $date->date('n', $timestamp)) {
// given month differs from parsed month
return false;
}
if ($parsed['day'] != $date->date('j', $timestamp)) {
// given day differs from parsed day
return false;
}
if ($parsed['hour'] != $date->date('G', $timestamp)) {
// given hour differs from parsed hour
return false;
}
if ($parsed['minute'] != $date->date('i', $timestamp)) {
// given minute differs from parsed minute
return false;
}
//.........这里部分代码省略.........