本文整理汇总了PHP中Date::format方法的典型用法代码示例。如果您正苦于以下问题:PHP Date::format方法的具体用法?PHP Date::format怎么用?PHP Date::format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Date
的用法示例。
在下文中一共展示了Date::format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findOneByHoursEvent
/**
* Find one by hours event
*
* @param integer $hours
* @param Date $date
* @return Cursor
*/
public function findOneByHoursEvent($hours = null, $date = null)
{
if (!$date) {
$currentDatetime = new \DateTime("now");
$hoursDatetime = new \DateTime("now");
$startDay = new \DateTime("now");
$finishDay = new \DateTime("now");
} else {
$currentDatetime = new \DateTime($date->format('Y-m-d H:s:i'));
$hoursDatetime = new \DateTime($date->format('Y-m-d H:s:i'));
$startDay = new \DateTime($date->format('Y-m-d H:s:i'));
$finishDay = new \DateTime($date->format('Y-m-d H:s:i'));
}
$hoursDatetime->add(new \DateInterval('PT' . $hours . 'H'));
$startDay->setTime(0, 0, 0);
$finishDay->setTime(23, 59, 59);
$currentDayEvents = $this->createQueryBuilder()->field('display')->equals(true)->field('date')->gte($startDay)->field('date')->lte($finishDay)->sort('date', 1)->getQuery()->execute();
$duration = 0;
foreach ($currentDayEvents as $event) {
$eventDate = new \DateTime($event->getDate()->format("Y-m-d H:i:s"));
if ($eventDate <= $hoursDatetime && $currentDatetime <= $eventDate->add(new \DateInterval('PT' . $event->getDuration() . 'M'))) {
return $event;
}
}
return null;
}
示例2: humanize
/**
* Returns human readable date.
*
* @param array $config An optional array with configuration options.
* @return string Formatted date.
*/
public function humanize($config = array())
{
$config = new ObjectConfig($config);
$config->append(array('date' => 'now', 'timezone' => date_default_timezone_get(), 'default' => \JText::_('Never'), 'smallest_period' => 'second'));
$result = $config->default;
if (!in_array($config->date, array('0000-00-00 00:00:00', '0000-00-00'))) {
$periods = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year');
$lengths = array(60, 60, 24, 7, 4.35, 12, 10);
$now = new \DateTime();
try {
$date = new Date(array('date' => $config->date, 'timezone' => 'UTC'));
$date->setTimezone(new \DateTimeZone($config->timezone));
if ($now != $date) {
// TODO: Use DateTime::getTimeStamp().
if ($now > $date) {
$difference = $now->format('U') - $date->format('U');
$tense = 'ago';
} else {
$difference = $date->format('U') - $now->format('U');
$tense = 'from now';
}
for ($i = 0; $difference >= $lengths[$i] && $i < 6; $i++) {
$difference /= $lengths[$i];
}
$difference = round($difference);
$period_index = array_search($config->smallest_period, $periods);
$omitted_periods = $periods;
array_splice($omitted_periods, $period_index);
if (in_array($periods[$i], $omitted_periods)) {
$difference = 1;
$i = $period_index;
}
if ($periods[$i] == 'day' && ($difference == 1 || $difference == 2)) {
if ($difference == 1) {
$result = \JText::_('Today');
} else {
$result = $tense == 'ago' ? \JText::_('Yesterday') : \JText::_('Tomorrow');
}
} else {
if ($difference != 1) {
$periods[$i] .= 's';
}
$result = sprintf(\JText::_('%d ' . $periods[$i] . ' ' . $tense), $difference);
}
} else {
$result = \JText::_('Now');
}
} catch (\Exception $e) {
}
}
return $result;
}
示例3: showDate
/**
* @param $date
* @param string $format
* @return string
*/
function showDate($date, $format = 'date')
{
$dt = new Date($date);
if (app::getLocale() == 'en') {
if ($format == 'date') {
return $dt->format('Y-m-d');
}
if ($format == 'text') {
return $dt->format('l F j, Y');
}
if ($format == 'text-court') {
return $dt->format('l F j');
}
return $dt->format($format);
}
if ($format == 'date') {
return $dt->format('d-m-Y');
}
if ($format == 'text') {
return $dt->format('l j F Y');
}
if ($format == 'text-court') {
return $dt->format('l j F');
}
return $dt->format($format);
}
示例4: _calculatePredictiveDate
protected function _calculatePredictiveDate()
{
// Прогностическая дата
$this->_datePredictive = clone $this->_dateOriginal;
if ($this->_datePredictive->format("Y-m-d H:i:s") <= "1919-07-01 01:59:00" || $this->_notime || $this->city === null) {
return;
}
// Рассчитываем дату и время с учетом поправки на летнее время
$connection = Yii::app()->db;
$command = $connection->createCommand("SELECT * FROM {{bazi_summertime}} WHERE `date_start` <= :date AND `date_end` >= :date AND `name` = :name");
$command->bindParam(":date", $this->_datePredictive->format("Y-m-d H:i:s"));
$command->bindParam(":name", $this->city->country);
//$command->bindParam(":date_end", $this->_datePredictive->format("Y-m-d H:i:s"));
$summerTime = $command->queryRow();
// Рассчитываем Поправку на часовой пояс (в минутах)
$command = $connection->createCommand("SELECT * FROM {{bazi_zone}} WHERE `line` = :line AND `date_start` <= :date AND `date_end` >= :date");
$command->bindParam(":line", $this->city->num, PDO::PARAM_INT);
$command->bindParam(":date", $this->_datePredictive->format("Y-m-d H:i:s"));
//$command->bindParam(":date_start", $this->_datePredictive->format("Y-m-d H:i:s"));
//$command->bindParam(":date_end", $this->_datePredictive->format("Y-m-d H:i:s"));
$lineInfo = $command->queryRow();
// Модифицируем дату
if ($summerTime) {
$this->_datePredictive->modify(($summerTime['minussec'] - $summerTime['plussec'] > 0 ? "+" : "-") . abs($summerTime['minussec'] - $summerTime['plussec']) . " seconds");
}
if ($lineInfo) {
$this->_datePredictive->modify((-($lineInfo['zone'] * 3600 - $this->city->r * 60) > 0 ? "+" : "-") . abs(-($lineInfo['zone'] * 3600 - $this->city->r * 60)) . " seconds");
}
}
示例5: get
public function get(array $ids = NULL)
{
$agent = $this->_section->agent();
$fids = $this->active_fields();
$documents = array();
$results = array('total' => 0, 'documents' => array());
$pagination = $this->pagination($ids);
$query = $agent->get_query_props(array_keys($fids), (array) $this->sorting())->select('d.created_on')->select('d.created_by_id')->select('dss.name')->join(array('datasources', 'dss'))->on('d.ds_id', '=', 'dss.id');
if (!empty($ids)) {
$query->where('d.id', 'in', $ids);
}
$query = $this->search_by_keyword($query);
$result = $query->limit($this->limit())->offset($this->offset())->execute()->as_array('id');
if (count($result) > 0) {
$results['total'] = $pagination->total_items;
foreach ($result as $id => $row) {
$data = array('id' => $id, 'published' => (bool) $row['published'], 'header' => $row['header'], 'created_on' => Date::format($row['created_on']), 'created_by_id' => $row['created_by_id']);
foreach ($fids as $field) {
if (isset($row[$field->id])) {
$data[$field->name] = $field->fetch_headline_value($row[$field->id], $id);
}
}
$document = new DataSource_Hybrid_Document($this->_section);
$document->id = $id;
$documents[$id] = $document->read_values($data)->set_read_only();
}
$results['documents'] = $documents;
}
return $results;
}
示例6: modified
public static function modified($format = false)
{
global $page;
global $settings;
$format = $format === false ? $settings['timestamp_format'] : $format;
return Date::format($page['mod_date_unix'], $format);
}
示例7: isValideByDate
public function isValideByDate($date)
{
if ($this->dateDeb->format('Y-m-d') <= $date && $this->dateFin->format('Y-m-d') >= $date) {
return TRUE;
}
return FALSE;
}
示例8: __set
/**
* Magic setter
*
* @param string $key
* @param mixed $value
*/
public function __set($key, $value)
{
switch ($key) {
// Date of birth
case 'dob':
$value = Date::format(Date::DATE_SQL, $value);
break;
// Always lowercase e-mail
// Always lowercase e-mail
case 'email':
$value = UTF8::strtolower($value);
break;
// Hash password
// Hash password
case 'password':
$visitor = Visitor::instance();
$value = $visitor->hash_password($value);
break;
// Set cleaned username when setting username
// Set cleaned username when setting username
case 'username':
$this->username_clean = Text::clean($value);
break;
}
parent::__set($key, $value);
}
示例9: format
function format($format)
{
global $prefs;
// Format the date
$return = parent::format($format);
// Translate the date if we are not already in english
// Divide the date into an array of strings by looking for dates elements (specified in $this->trad)
$words = preg_split('/(' . implode('|', $this->trad) . ')/', $return, -1, PREG_SPLIT_DELIM_CAPTURE);
// For each strings in $words array...
$return = '';
foreach ($words as $w) {
if (array_key_exists($w, $this->translated_trad)) {
// ... we've loaded this previously
$return .= $this->translated_trad["{$w}"];
} else {
if (in_array($w, $this->trad)) {
// ... or we have a date element that needs a translation
$t = tra($w, '', true);
$this->translated_trad["{$w}"] = $t;
$return .= $t;
} else {
// ... or we have a string that should not be translated
$return .= $w;
}
}
}
return $return;
}
示例10: content
/**
* Render content.
*
* @return string
*/
public function content()
{
ob_start();
// Stamp
echo HTML::time(Date('l ', $this->event->stamp_begin) . Date::format('DDMMYYYY', $this->event->stamp_begin), $this->event->stamp_begin, true);
// Location
if ($this->event->venue) {
echo ' @ ', HTML::anchor(Route::model($this->event->venue), HTML::chars($this->event->venue->name)), ', ', HTML::chars($this->event->venue->city_name);
} elseif ($this->event->venue_name) {
echo ' @ ', $this->event->venue_url ? HTML::anchor($this->event->venue_url, $this->event->venue_name) : HTML::chars($this->event->venue_name), $this->event->city_name ? ', ' . HTML::chars($this->event->city_name) : '';
} elseif ($this->event->city_name) {
echo ' @ ', HTML::chars($this->event->city_name);
}
// Flyer
if ($flyer = $this->event->flyer()) {
echo '<figure>', HTML::image($flyer->image_url(Model_Image::SIZE_THUMBNAIL)), '</figure>';
} elseif ($this->event->flyer_front_url) {
echo '<figure>', HTML::image($this->event->flyer_front_url, ['class' => 'img-responsive']), '</figure>';
}
// Favorites
if ($this->event->favorite_count) {
echo '<span class="stats"><i class="fa fa-heart"></i> ' . $this->event->favorite_count . '</span>';
}
return ob_get_clean();
}
示例11: handle
/**
* Handle an error.
*
* @param int $errorStatus Error status code
* @param string $errorMsg Error message
* @param string $errorFile Error script file
* @param int $errorLine Error script line
* @throws ApiException API exception
*/
public static function handle($errorStatus, $errorMsg, $errorFile, $errorLine)
{
// Build the complete error message
$mailMsg = '<b>--- Spotzi ErrorHandler ---</b>' . PHP_EOL . PHP_EOL;
$mailMsg .= 'Date: ' . Date::format() . PHP_EOL;
$mailMsg .= 'Error status: ' . $errorStatus . PHP_EOL;
$mailMsg .= 'Error message: ' . $errorMsg . PHP_EOL;
$mailMsg .= 'Script name: ' . $errorFile . PHP_EOL;
$mailMsg .= 'Line number: ' . $errorLine . PHP_EOL;
//$mailMsg .= 'Request referer: ' . REQUEST_REFERER . PHP_EOL;
//$mailMsg .= 'Request URL: ' . URL_BASE . ltrim(REQUEST_URI, '/') . PHP_EOL;
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$mailMsg .= 'User agent: ' . $_SERVER['HTTP_USER_AGENT'];
}
// Determine whether debug mode is active
if (debugMode()) {
// In case debug mode is active, set the error message as the frontend message
debugPrint($mailMsg);
} else {
// Send the error email when needed
if (HttpStatus::emailStatus($errorStatus)) {
// Prepare the error mailer
Mail::addMailer(EMAIL_HOST, EMAIL_PORT, EMAIL_ERROR_FROM, EMAIL_ERROR_FROM_PASSWORD, BRAND_PRODUCT);
// Send the error email
Mail::send(EMAIL_ERROR_RECIPIENT, EMAIL_ERROR_FROM, EMAIL_ERROR_SUBJECT, nl2br($mailMsg));
}
throw new ApiException($errorStatus, $errorMsg);
}
}
示例12: updateBludit
function updateBludit()
{
global $Site;
global $dbPosts;
// Check if Bludit need to be update.
if ($Site->currentBuild() < BLUDIT_BUILD || isset($_GET['update'])) {
// --- Update dates ---
foreach ($dbPosts->db as $key => $post) {
$date = Date::format($post['date'], 'Y-m-d H:i', DB_DATE_FORMAT);
if ($date !== false) {
$dbPosts->setPostDb($key, 'date', $date);
}
}
$dbPosts->save();
// --- Update directories ---
$directories = array(PATH_POSTS, PATH_PAGES, PATH_PLUGINS_DATABASES, PATH_UPLOADS_PROFILES, PATH_UPLOADS_THUMBNAILS, PATH_TMP);
foreach ($directories as $dir) {
// Check if the directory is already created.
if (!file_exists($dir)) {
// Create the directory recursive.
mkdir($dir, DIR_PERMISSIONS, true);
}
}
// Set and save the database.
$Site->set(array('currentBuild' => BLUDIT_BUILD));
Log::set('updateBludit' . LOG_SEP . 'System updated');
}
}
示例13: testSettingDefaultFormat
public function testSettingDefaultFormat()
{
$ts = mktime(12, 30, 0, 7, 4, 1983);
$date = new Date($ts);
$date->setFormat('d.m.Y H:i:s');
return $this->assertEqual($date->format(), '04.07.1983 12:30:00');
}
示例14: handle
/**
* Handle an error.
*
* @param int $errorNo Error number
* @param string $errorMsg Error message
* @param string $errorFile Error script file
* @param int $errorLine Error script line
*/
public static function handle($errorNo, $errorMsg, $errorFile, $errorLine)
{
// Build the complete error message
$mailMsg = '<b>--- ' . BRAND_NAME . ' ErrorHandler ---</b>' . PHP_EOL . PHP_EOL;
$mailMsg .= 'Date: ' . Date::format() . PHP_EOL;
$mailMsg .= 'Error number: ' . $errorNo . PHP_EOL;
$mailMsg .= 'Error type: ' . self::$errortypes[$errorNo] . PHP_EOL;
$mailMsg .= 'Error message: ' . $errorMsg . PHP_EOL;
$mailMsg .= 'Script name: ' . $errorFile . PHP_EOL;
$mailMsg .= 'Line number: ' . $errorLine . PHP_EOL;
$mailMsg .= 'Request URL: ' . URL_BASE . ltrim(REQUEST_URI, '/') . PHP_EOL;
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$mailMsg .= 'User agent: ' . $_SERVER['HTTP_USER_AGENT'];
}
// Determine whether debug mode is active
if (debugMode()) {
// In case debug mode is active, set the error message as the frontend message
debugPrint($mailMsg);
} else {
// Prepare the error mailer
Mail::addMailer(EMAIL_HOST, EMAIL_PORT, EMAIL_ERROR_FROM, EMAIL_ERROR_FROM_PASSWORD, BRAND_PRODUCT);
// Send the error email
Mail::send(EMAIL_ERROR_RECIPIENT, EMAIL_ERROR_FROM, EMAIL_ERROR_SUBJECT, nl2br($mailMsg));
// In case of a fatal error, stop execution and show the general frontend message
if ($errorNo !== E_WARNING && $errorNo !== E_NOTICE && $errorNo !== E_USER_NOTICE && $errorNo !== E_STRICT) {
debugPrint(__('An unexpected error has occured.<br>If this error keeps occuring, please contact your vendor for assistance') . __('<br>Message: %s', $errorMsg));
}
}
}
示例15: fetch_headline_value
public function fetch_headline_value($value, $document_id)
{
if (!empty($value)) {
return Date::format($value, 'j F Y H:i:s');
}
return parent::fetch_headline_value($value, $document_id);
}