本文整理匯總了PHP中IntlDateFormatter::formatObject方法的典型用法代碼示例。如果您正苦於以下問題:PHP IntlDateFormatter::formatObject方法的具體用法?PHP IntlDateFormatter::formatObject怎麽用?PHP IntlDateFormatter::formatObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類IntlDateFormatter
的用法示例。
在下文中一共展示了IntlDateFormatter::formatObject方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: render
/**
* Renders grid column
*
* @param \Magento\Framework\Object $row
* @return string
*/
public function render(\Magento\Framework\Object $row)
{
//@todo: check this logic manually
if ($data = $row->getData($this->getColumn()->getIndex())) {
switch ($this->getColumn()->getPeriodType()) {
case 'month':
$dateFormat = 'yyyy-MM';
break;
case 'year':
$dateFormat = 'yyyy';
break;
default:
$dateFormat = \Magento\Framework\Stdlib\DateTime::DATE_INTERNAL_FORMAT;
break;
}
$format = $this->_getFormat();
try {
$data = $this->getColumn()->getGmtoffset() ? \IntlDateFormatter::formatObject($this->_localeDate->date(new \DateTime($data)), $format) : \IntlDateFormatter::formatObject($this->_localeDate->date(new \DateTime($data), null, false), $format);
} catch (\Exception $e) {
$data = $this->getColumn()->getTimezone() ? \IntlDateFormatter::formatObject($this->_localeDate->date(new \DateTime($data)), $format) : \IntlDateFormatter::formatObject($this->_localeDate->date(new \DateTime($data), null, false), $format);
}
return $data;
}
return $this->getColumn()->getDefault();
}
示例2: formatObject
/**
* {@inheritdoc}
*/
public function formatObject($object, $format = null, $locale = null)
{
if ($this->useIntlFormatObject) {
return \IntlDateFormatter::formatObject($object, $format, $locale);
}
return $this->doFormatObject($object, $format, $locale);
}
示例3: render
/**
* Renders grid column
*
* @param \Magento\Framework\Object $row
* @return string
*/
public function render(\Magento\Framework\Object $row)
{
if ($data = $row->getData($this->getColumn()->getIndex())) {
$format = $this->_getFormat();
return \IntlDateFormatter::formatObject($this->_localeDate->date(new \DateTime($data)), $format);
}
return $this->getColumn()->getDefault();
}
示例4: getEscapedValue
/**
* @param string|null $index
* @return string
*/
public function getEscapedValue($index = null)
{
$value = $this->getValue($index);
if ($value instanceof \DateTime) {
return \IntlDateFormatter::formatObject($value, $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT));
}
return $value;
}
示例5: formatDeliveryTime
/**
* Format given time [+ date] in current locale without changing timezone
*
* @param string $time
* @param string $date
* @return string
*/
public function formatDeliveryTime($time, $date = null)
{
if (!empty($date)) {
$time = $date . ' ' . $time;
}
$format = $this->_localeDate->getTimeFormat(\IntlDateFormatter::SHORT);
return \IntlDateFormatter::formatObject($this->_localeDate->date(new \DateTime($time)), $format);
}
示例6: formatObject
/**
* {@inheritdoc}
*/
public function formatObject($object, $format = null, $locale = null)
{
$locale = (null === $locale) ? $this->getLocaleResolver()->getLocale() : $locale;
if ($this->useIntlFormatObject) {
return \IntlDateFormatter::formatObject($object, $format, $locale);
}
return $this->doFormatObject($object, $format, $locale);
}
示例7: testFormatObject
/**
* @param \IntlCalendar|\DateTime $object
* @param string|int|array|null $format
* @param string|null $locale
* @param boolean $useIntlFormatObject
* @dataProvider dataProviderFormatObject
*/
public function testFormatObject($object, $format = null, $locale = null, $useIntlFormatObject = false)
{
$dateTimeFormatter = $this->objectManager->getObject('Magento\\Framework\\Stdlib\\DateTime\\DateTimeFormatter', ['useIntlFormatObject' => $useIntlFormatObject]);
$reflection = new \ReflectionClass(get_class($dateTimeFormatter));
$reflectionProperty = $reflection->getProperty('localeResolver');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($dateTimeFormatter, $this->localeResolverMock);
$this->assertEquals(\IntlDateFormatter::formatObject($object, $format, null === $locale ? 'fr-FR' : $locale), $dateTimeFormatter->formatObject($object, $format, $locale));
}
示例8: testRender
public function testRender()
{
$testCacheValue = '1433259723';
$testDatetime = (new \DateTime(null, new \DateTimeZone('UTC')))->setTimestamp($testCacheValue);
$formattedDate = \IntlDateFormatter::formatObject($testDatetime);
$htmlId = 'test_HTML_id';
$label = 'test_label';
$cacheMock = $this->getMockBuilder('Magento\\Framework\\App\\CacheInterface')->disableOriginalConstructor()->setMethods(['load', 'getFrontend', 'remove', 'save', 'clean'])->getMock();
$cacheMock->expects($this->any())->method('load')->willReturn($testCacheValue);
$localeDateMock = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface')->disableOriginalConstructor()->getMock();
$localeDateMock->expects($this->any())->method('date')->willReturn($testDatetime);
$localeDateMock->expects($this->any())->method('getDateTimeFormat')->willReturn(null);
$elementMock = $this->getMockBuilder('Magento\\Framework\\Data\\Form\\Element\\AbstractElement')->disableOriginalConstructor()->setMethods(['getHtmlId', 'getLabel'])->getMock();
$elementMock->expects($this->any())->method('getHtmlId')->willReturn($htmlId);
$elementMock->expects($this->any())->method('getLabel')->willReturn($label);
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
$notification = $objectManager->getObject('Magento\\Config\\Block\\System\\Config\\Form\\Field\\Notification', ['cache' => $cacheMock, 'localeDate' => $localeDateMock]);
$html = $notification->render($elementMock);
$this->assertEquals('<tr id="row_' . $htmlId . '">' . '<td class="label">' . '<label for="' . $htmlId . '">' . $label . '</label>' . '</td>' . '<td class="value">' . $formattedDate . '</td>' . '<td class="scope-label"></td>' . '<td class=""></td>' . '</tr>', $html);
}
示例9: render
/**
* Renders grid column
*
* @param \Magento\Framework\Object $row
* @return string
*/
public function render(\Magento\Framework\Object $row)
{
if ($data = $row->getData($this->getColumn()->getIndex())) {
switch ($this->getColumn()->getPeriodType()) {
case 'month':
$data = $data . '-01';
break;
case 'year':
$data = $data . '-01-01';
break;
}
$format = $this->_getFormat();
if ($this->getColumn()->getGmtoffset() || $this->getColumn()->getTimezone()) {
$date = $this->_localeDate->date(new \DateTime($data));
} else {
$date = $this->_localeDate->date(new \DateTime($data), null, false);
}
return \IntlDateFormatter::formatObject($date, $format);
}
return $this->getColumn()->getDefault();
}
示例10: gettext
if ($_SESSION["pit_on"] == "True") {
?>
<div class="last_regulation_view"><?php
echo gettext("Last regulation on");
?>
<b><?php
echo IntlDateFormatter::formatObject($pit_time_stamp, array(IntlDateFormatter::SHORT, IntlDateFormatter::MEDIUM), $_SESSION["locale"]);
?>
</b></div><?php
}
?>
<div class="last_measure_view"><?php
echo gettext("Last measurement on");
?>
<b><?php
echo IntlDateFormatter::formatObject($time_stamp, array(IntlDateFormatter::SHORT, IntlDateFormatter::MEDIUM), $_SESSION["locale"]);
?>
</b>
<?php
if ($_SESSION["showcpulast"] == "True") {
echo "<br>";
$cpuload = new CPULoad();
$cpuload->get_load();
$CPULOAD = round($cpuload->load["cpu"], 1);
echo gettext("CPU utilization") . ": <b>" . $CPULOAD . "% / " . get_cputemp() . $temp_unit_short;
"</b>";
}
?>
</div>
<br>
<div class="clear"></div>
示例11: DateTime
<?php
$obj = new DateTime('2013-08-20T12:34:56');
print IntlDateFormatter::formatObject($obj, 'eeee dd MMMM y', 'es_ES') . "\n";
print IntlDateFormatter::formatObject($obj, IntlDateFormatter::FULL, 'fr_FR') . "\n";
// First element is date format, second is time format
$formats = array(IntlDateFormatter::FULL, IntlDateFormatter::SHORT);
print IntlDateFormatter::formatObject($obj, $formats, 'de_DE') . "\n";
示例12: array
<?php
$bits = array();
$bits['Hour'] = array('a' => 'Ante/Post Meridiem designation', 'h' => 'Hour, 12-hour clock (1 - 12)', 'K' => 'Hour, 12-hour clock (0 - 11)', 'H' => 'Hour, 24-hour clock (0 - 23)', 'k' => 'Hour, 24-hour clock (1 - 24)');
$bits['Minute'] = array('m' => 'Minute (0 - 59)');
$bits['Second'] = array('s' => 'Second (0 - 59)', 'S' => 'Decisecond (0 - 9)', 'SS' => 'Centisecond (00 - 99)', 'SSS' => 'Millisecond (000 - 999)', 'A' => 'Milliseconds in day');
$bits['Day'] = array('d' => 'Day of month (1 - 31)', 'D' => 'Day of year (1 - 366)', 'EEEEE' => 'Day of week, short abbreviation', 'EEE' => 'Day of week, long abbreviation', 'EEEE' => 'Day of week, name', 'e' => 'Day of week, number (0 or 1 to 6 or 7, localized)', 'F' => 'Day of week in the month (e.g. 3 for "third wednesday")', 'g' => 'Modified Julian Day');
$bits['Week'] = array('w' => 'Week of Year, with localized week start (1 - 52)', 'W' => 'Week of Month (1 - 5)');
$bits['Month'] = array('M' => 'Month (1 - 12)', 'MMMMM' => 'Month, short abbreviation', 'MMM' => 'Month, long abbreviation', 'MMMM' => 'Month, name');
$bits['Year'] = array('y' => 'Year, 4-digit', 'yy' => 'Year, 2-digit');
$bits['Time Zone'] = array('z' => 'Time zone, including Summer Time, abbreviated', 'zzzz' => 'Time zone, including Summer Time, full name', 'Z' => 'Time zone, RFC-822 format', 'ZZZZ' => 'Time zone, as GMT offset', 'ZZZZZ' => 'Time zone, ISO-8601 format', 'v' => 'Time zone, not including Summer Time, abbreviated', 'vvvv' => 'Time zone, not including Summer Time, full name', 'VVVV' => 'Time zone, as location');
$bits['Other'] = array('Q' => 'Quarter, number', 'QQQ' => 'Quarter, number with prefix', 'QQQQ' => 'Quarter, as words', 'G' => 'Era (BC, AD)', "''" => 'Single quote');
/*
standalone
c for e
q for Q
L for M
*/
$when = new DateTime('2004-03-18T15:08:07 America/New_York');
print "|Type|Character|Description|Example\n";
foreach ($bits as $type => $stuff) {
foreach ($stuff as $char => $desc) {
$example = IntlDateFormatter::formatObject($when, $char, 'en_US');
print "|{$type}|{$char}|{$desc}|{$example}\n";
}
}
示例13: testFormatObject
/**
* @param \IntlCalendar|\DateTime $object
* @param string|int|array|null $format
* @param string|null $locale
* @dataProvider dataProviderFormatObject
*/
public function testFormatObject($object, $format = null, $locale = null)
{
$this->assertEquals(\IntlDateFormatter::formatObject($object, $format, $locale), $this->dateTimeFormatter->formatObject($object, $format, $locale));
}
示例14: _showLastExecutionTime
/**
* Add refresh statistics links
*
* @param string $flagCode
* @param string $refreshCode
* @return $this
*/
protected function _showLastExecutionTime($flagCode, $refreshCode)
{
$flag = $this->_objectManager->create('Magento\\Reports\\Model\\Flag')->setReportFlagCode($flagCode)->loadSelf();
$updatedAt = 'undefined';
if ($flag->hasData()) {
$updatedAt = \IntlDateFormatter::formatObject($this->_objectManager->get('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface')->scopeDate(0, $flag->getLastUpdate(), true));
}
$refreshStatsLink = $this->getUrl('reports/report_statistics');
$directRefreshLink = $this->getUrl('reports/report_statistics/refreshRecent', ['code' => $refreshCode]);
$this->messageManager->addNotice(__('Last updated: %1. To refresh last day\'s <a href="%2">statistics</a>, ' . 'click <a href="%3">here</a>.', $updatedAt, $refreshStatsLink, $directRefreshLink));
return $this;
}
示例15: ini_set
ini_set("intl.default_locale", "pt_PT");
ini_set("date.timezone", "Europe/Lisbon");
var_dump(IntlDateFormatter::formatObject());
var_dump(IntlDateFormatter::formatObject(1));
var_dump(IntlDateFormatter::formatObject(new stdclass()));
class A extends IntlCalendar
{
function __construct()
{
}
}
var_dump(IntlDateFormatter::formatObject(new A()));
class B extends DateTime
{
function __construct()
{
}
}
var_dump(IntlDateFormatter::formatObject(new B()));
$cal = IntlCalendar::createInstance();
var_dump(IntlDateFormatter::formatObject($cal, -2));
var_dump(IntlDateFormatter::formatObject($cal, array()));
var_dump(IntlDateFormatter::formatObject($cal, array(1, 2, 3)));
var_dump(IntlDateFormatter::formatObject($cal, array(array(), 1)));
var_dump(IntlDateFormatter::formatObject($cal, array(1, -2)));
var_dump(IntlDateFormatter::formatObject($cal, ""));
var_dump(IntlDateFormatter::formatObject($cal, "YYYY", array()));
?>
==DONE==