本文整理汇总了PHP中Zend_Locale_Format::getDateTime方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Locale_Format::getDateTime方法的具体用法?PHP Zend_Locale_Format::getDateTime怎么用?PHP Zend_Locale_Format::getDateTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Locale_Format
的用法示例。
在下文中一共展示了Zend_Locale_Format::getDateTime方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testgetDateTime
/**
* Tests getDateTime
*/
public function testgetDateTime()
{
try {
$value = Zend_Locale_Format::getDateTime('no content');
$this->fail("exception expected");
} catch (Zend_Locale_Exception $e) {
// success
}
$this->assertTrue(is_array(Zend_Locale_Format::getDateTime('10.11.2006 13:14:55', array('date_format' => 'dd.MM.yyyy HH:mm:ss'))));
$options = array('date_format' => 'dd.MM.yy h:mm:ss a', 'locale' => 'en');
$this->assertTrue(is_array(Zend_Locale_Format::getDateTime('15.10.09 11:14:55 am', $options)));
$this->assertTrue(is_array(Zend_Locale_Format::getDateTime('15.10.09 12:14:55 am', $options)));
$this->assertTrue(is_array(Zend_Locale_Format::getDateTime('15.10.09 11:14:55 pm', $options)));
$this->assertTrue(is_array(Zend_Locale_Format::getDateTime('15.10.09 12:14:55 pm', $options)));
try {
$value = Zend_Locale_Format::getDateTime('15.10.09 13:14:55', array('date_format' => 'nocontent'));
$this->fail("exception expected");
} catch (Zend_Locale_Exception $e) {
// success
}
try {
$value = Zend_Locale_Format::getDateTime('15.10.09 13:14:55', array('date_format' => 'ZZZZ'));
$this->fail("exception expected");
} catch (Zend_Locale_Exception $e) {
// success
}
$value = Zend_Locale_Format::getDateTime('15.10.09 13:14:55', array('date_format' => 'dd.MM.yy HH:mm:ss.x'));
$this->assertEquals(15, $value['day']);
$this->assertEquals(10, $value['month']);
$this->assertEquals(2009, $value['year']);
$this->assertEquals(13, $value['hour']);
$this->assertEquals(14, $value['minute']);
$this->assertEquals(55, $value['second']);
$this->assertEquals(8, count(Zend_Locale_Format::getDateTime('15.10.09 13:14:55', array('date_format' => 'dd.MM.yy HH:mm:ss'))));
$value = Zend_Locale_Format::getDateTime('15.10.09 13:14:55', array('date_format' => 'dd.MM.yy HH:mm:ss'));
$this->assertEquals(15, $value['day']);
$this->assertEquals(10, $value['month']);
$this->assertEquals(2009, $value['year']);
$this->assertEquals(13, $value['hour']);
$this->assertEquals(14, $value['minute']);
$this->assertEquals(55, $value['second']);
$value = Zend_Locale_Format::getDateTime('151009131455', array('date_format' => 'dd.MM.yy HH:mm:ss'));
$this->assertEquals(15, $value['day']);
$this->assertEquals(10, $value['month']);
$this->assertEquals(2009, $value['year']);
$this->assertEquals(13, $value['hour']);
$this->assertEquals(14, $value['minute']);
$this->assertEquals(55, $value['second']);
}
示例2: _calculate
//.........这里部分代码省略.........
$format = Zend_Locale_Data::getContent($locale, 'time', array('gregorian', 'medium'));
$parsed = Zend_Locale_Format::getTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
if ($calc != 'set') {
$month = 1;
$day = 1;
$year = 1970;
}
return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $month, $day, $year, true), $this->mktime($hour, $minute, $second, $month, $day, $year, true), false);
} catch (Zend_Locale_Exception $e) {
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date);
}
break;
case self::TIME_SHORT:
try {
$format = Zend_Locale_Data::getContent($locale, 'time', array('gregorian', 'short'));
$parsed = Zend_Locale_Format::getTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
if ($calc != 'set') {
$month = 1;
$day = 1;
$year = 1970;
}
if (!isset($parsed['second'])) {
$parsed['second'] = 0;
}
return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], $month, $day, $year, true), $this->mktime($hour, $minute, $second, $month, $day, $year, true), false);
} catch (Zend_Locale_Exception $e) {
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date);
}
break;
case self::DATETIME:
try {
$parsed = Zend_Locale_Format::getDateTime($date, array('locale' => $locale, 'format_type' => 'iso', 'fix_date' => true));
if ($calc == 'set' || $calc == 'cmp') {
--$parsed['month'];
--$month;
--$parsed['day'];
--$day;
$parsed['year'] -= 1970;
$year -= 1970;
}
return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), $hour);
} catch (Zend_Locale_Exception $e) {
require_once 'Zend/Date/Exception.php';
throw new Zend_Date_Exception($e->getMessage(), 0, $e, $date);
}
break;
case self::DATETIME_FULL:
try {
$format = Zend_Locale_Data::getContent($locale, 'datetime', array('gregorian', 'full'));
$parsed = Zend_Locale_Format::getDateTime($date, array('date_format' => $format, 'format_type' => 'iso', 'locale' => $locale));
if ($calc == 'set' || $calc == 'cmp') {
--$parsed['month'];
--$month;
--$parsed['day'];
--$day;
$parsed['year'] -= 1970;
$year -= 1970;
}
if (!isset($parsed['second'])) {
$parsed['second'] = 0;
}
return $this->_assign($calc, $this->mktime($parsed['hour'], $parsed['minute'], $parsed['second'], 1 + $parsed['month'], 1 + $parsed['day'], 1970 + $parsed['year'], true), $this->mktime($hour, $minute, $second, 1 + $month, 1 + $day, 1970 + $year, true), $hour);
} catch (Zend_Locale_Exception $e) {
require_once 'Zend/Date/Exception.php';
示例3: _normalize
/**
* Reads a localized value, normalizes and returns it.
* Returns an empty string if no value is passed.
* @param mixed $value
* @param string $type (boolean|date|time|integer|float|decimal|currency)
* @return mixed
*/
private function _normalize($value, $type, $num_of_decimals)
{
if (strlen($value) == 0) {
return '';
}
switch ($type) {
case 'boolean':
$yes_no = Zend_Locale_Data::getContent($this->_locale_engine, 'questionstrings');
$yes_regexp = '/^(' . str_replace(':', '|', $yes_no['yes']) . ')$/i';
if (preg_match($yes_regexp, $value)) {
return 1;
}
return 0;
case 'date':
$date = Zend_Locale_Format::getDate($value, array('locale' => $this->_locale_engine, 'fix_date' => true));
$date['month'] = str_pad($date['month'], 2, 0, STR_PAD_LEFT);
$date['day'] = str_pad($date['day'], 2, 0, STR_PAD_LEFT);
return "{$date['year']}-{$date['month']}-{$date['day']}";
case 'time':
$date_format = Zend_Locale_Format::getTimeFormat($this->_locale_engine);
$date = Zend_Locale_Format::getDate($value, array('date_format' => $date_format, 'locale' => $this->_locale_engine));
if (!isset($date['hour'])) {
$date['hour'] = '00';
}
if (!isset($date['minute'])) {
$date['minute'] = '00';
}
if (!isset($date['second'])) {
$date['second'] = '00';
}
return "{$date['hour']}:{$date['minute']}:{$date['second']}";
case 'datetime':
$date = Zend_Locale_Format::getDateTime($value, array('locale' => $this->_locale_engine, 'fix_date' => true));
$date['month'] = str_pad($date['month'], 2, 0, STR_PAD_LEFT);
$date['day'] = str_pad($date['day'], 2, 0, STR_PAD_LEFT);
$date['hour'] = str_pad($date['hour'], 2, 0, STR_PAD_LEFT);
$date['minute'] = str_pad($date['minute'], 2, 0, STR_PAD_LEFT);
$date['second'] = str_pad($date['second'], 2, 0, STR_PAD_LEFT);
return "{$date['year']}-{$date['month']}-{$date['day']} {$date['hour']}:{$date['minute']}:{$date['second']}";
break;
case 'integer':
return Zend_Locale_Format::getInteger($value, array('locale' => $this->_locale_engine));
case 'float':
if ($num_of_decimals === null) {
$num_of_decimals = 3;
}
return Zend_Locale_Format::getFloat($value, array('precision' => $num_of_decimals, 'locale' => $this->_locale_engine));
case 'decimal':
if ($num_of_decimals === null) {
$num_of_decimals = 2;
}
return Zend_Locale_Format::getFloat($value, array('precision' => $num_of_decimals, 'locale' => $this->_locale_engine));
}
return $value;
}