当前位置: 首页>>代码示例>>PHP>>正文


PHP Date类代码示例

本文整理汇总了PHP中Date的典型用法代码示例。如果您正苦于以下问题:PHP Date类的具体用法?PHP Date怎么用?PHP Date使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Date类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: get_reference_date

 private static function get_reference_date()
 {
     $reference_date = new Date();
     $life_time = self::get_life_time();
     $reference_date->set_day($reference_date->get_day() - $life_time);
     return $reference_date;
 }
开发者ID:AroundPBT,项目名称:PHPBoost,代码行数:7,代码来源:SitemapXMLFileService.class.php

示例2: __construct

 function __construct()
 {
     // Check auto-maintenance settings
     $aConf = $GLOBALS['_MAX']['CONF'];
     $this->isAutoMaintenanceEnabled = !empty($aConf['maintenance']['autoMaintenance']);
     // Get time 1 hour ago
     $oServiceLocator =& OA_ServiceLocator::instance();
     $oNow = $oServiceLocator->get('now');
     if ($oNow) {
         $oOneHourAgo = new Date($oNow);
     } else {
         $oOneHourAgo = new Date();
     }
     $oOneHourAgo->subtractSpan(new Date_Span('0-1-0-0'));
     // Get last runs
     $oLastCronRun = OX_Maintenance::getLastScheduledRun();
     $oLastRun = OX_Maintenance::getLastRun();
     // Reset minutes and seconds
     if (isset($oLastCronRun)) {
         $oLastCronRun->setMinute(0);
         $oLastCronRun->setSecond(0);
     }
     if (isset($oLastRun)) {
         $oLastRun->setMinute(0);
         $oLastRun->setSecond(0);
     }
     // Check if any kind of maintenance was run
     if (isset($oLastCronRun) && !$oOneHourAgo->after($oLastCronRun)) {
         $this->isScheduledMaintenanceRunning = true;
     } elseif (isset($oLastRun) && !$oOneHourAgo->after($oLastRun)) {
         $this->isAutoMaintenanceRunning = true;
     }
 }
开发者ID:Spark-Eleven,项目名称:revive-adserver,代码行数:33,代码来源:Status.php

示例3: RSSItems

 /**
  * Gets a list of all the items in the RSS feed given a user-provided URL, limit, and date format
  *
  * @return ArrayList
  */
 public function RSSItems()
 {
     if (!$this->FeedURL) {
         return false;
     }
     $doc = new DOMDocument();
     @$doc->load($this->FeedURL);
     $items = $doc->getElementsByTagName('item');
     $feeds = array();
     foreach ($items as $node) {
         $itemRSS = array('title' => $node->getElementsByTagName('title')->item(0)->nodeValue, 'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue, 'link' => $node->getElementsByTagName('link')->item(0)->nodeValue, 'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue);
         $feeds[] = $itemRSS;
     }
     $output = ArrayList::create(array());
     $count = 0;
     foreach ($feeds as $item) {
         if ($count >= $this->Count) {
             break;
         }
         // Cast the Date
         $date = new Date('Date');
         $date->setValue($item['date']);
         // Cast the Title
         $title = new Text('Title');
         $title->setValue($item['title']);
         $output->push(new ArrayData(array('Title' => $title, 'Date' => $date->Format($this->DateFormat), 'Link' => $item['link'])));
         $count++;
     }
     return $output;
 }
开发者ID:helpfulrobot,项目名称:unclecheese-dashboard,代码行数:35,代码来源:DashboardRSSFeedPanel.php

示例4: __construct

 public function __construct($oStart, $oEnd, $aEntityParams)
 {
     $oNow = new Date();
     $this->oStart = $oNow->before($oStart) ? $oNow : $oStart;
     $this->oEnd = $oNow->before($oEnd) ? $oNow : $oEnd;
     $this->parseEntityParams($aEntityParams);
 }
开发者ID:SamWinchester,项目名称:revive-adserver,代码行数:7,代码来源:apGraph.php

示例5: MAX_getDatesByPeriodLimitStart

function MAX_getDatesByPeriodLimitStart($period, $limit, $start)
{
    $begin = $limit + $start - 1;
    $end = $start;
    switch ($period) {
        case 'daily':
            $dayBegin = new Date();
            $dayBegin->subtractSpan(new Date_Span("{$begin}, 0, 0, 0"));
            $dayEnd = new Date();
            $dayBegin->subtractSpan(new Date_Span("{$end}, 0, 0, 0"));
            break;
        case 'weekly':
            $dayBegin = new Date(Date_Calc::prevDay());
            $dayEnd = new Date(Date_Calc::prevDay());
            break;
        case 'monthly':
            $dayBegin = new Date();
            $dayBegin->subtractSpan(new Date_Span('6, 0, 0, 0'));
            $dayEnd = new Date();
            break;
        case 'allstats':
        default:
            $dayBegin = null;
            $dayEnd = null;
    }
    $aDates = array();
    $aDates['day_begin'] = is_object($dayBegin) ? $dayBegin->format('%Y-%m-%d') : '';
    $aDates['day_end'] = is_object($dayEnd) ? $dayEnd->format('%Y-%m-%d') : '';
    return $aDates;
}
开发者ID:Jaree,项目名称:revive-adserver,代码行数:30,代码来源:stats.php

示例6: testDeliveryBlocked

 /**
  * A method to test the deliveryBlocked() method.
  */
 function testDeliveryBlocked()
 {
     OA_setTimeZoneUTC();
     $aDeliveryLimitation = array('ad_id' => 1, 'logical' => 'and', 'type' => 'deliveryLimitations:Time:Hour', 'comparison' => '=~', 'data' => '1,5,7,20', 'executionorder' => 1);
     $oLimitationHour = OA_Maintenance_Priority_DeliveryLimitation_Factory::factory($aDeliveryLimitation);
     $oDate = new Date('2006-02-07 23:15:45');
     for ($i = 0; $i < 24; $i++) {
         $oDate->addSeconds(SECONDS_PER_HOUR);
         if ($i == 1 || $i == 5 || $i == 7 || $i == 20) {
             $this->assertFalse($oLimitationHour->deliveryBlocked($oDate));
         } else {
             $this->assertTrue($oLimitationHour->deliveryBlocked($oDate));
         }
     }
     // Test timezone
     $aDeliveryLimitation = array('ad_id' => 1, 'logical' => 'and', 'type' => 'deliveryLimitations:Time:Hour', 'comparison' => '=~', 'data' => '1,5,7,20@Europe/Rome', 'executionorder' => 1);
     $oLimitationHour = OA_Maintenance_Priority_DeliveryLimitation_Factory::factory($aDeliveryLimitation);
     $oDate = new Date('2006-02-07 23:15:45');
     for ($i = 0; $i < 24; $i++) {
         $oDate->addSeconds(SECONDS_PER_HOUR);
         if ($i == 0 || $i == 4 || $i == 6 || $i == 19) {
             $this->assertFalse($oLimitationHour->deliveryBlocked($oDate));
         } else {
             $this->assertTrue($oLimitationHour->deliveryBlocked($oDate));
         }
     }
     OA_setTimeZoneLocal();
 }
开发者ID:Spark-Eleven,项目名称:revive-adserver,代码行数:31,代码来源:MpeTimeHour.plg.test.php

示例7: build_view

    public function build_view()
    {
        $now = new Date();
        $authorized_categories = NewsService::get_authorized_categories(Category::ROOT_CATEGORY);
        $news_config = NewsConfig::load();
        $condition = 'WHERE id_category IN :authorized_categories
		' . (!NewsAuthorizationsService::check_authorizations()->moderation() ? ' AND author_user_id = :user_id' : '') . '
		AND (approbation_type = 0 OR (approbation_type = 2 AND (start_date > :timestamp_now OR (end_date != 0 AND end_date < :timestamp_now))))';
        $parameters = array('authorized_categories' => $authorized_categories, 'user_id' => AppContext::get_current_user()->get_id(), 'timestamp_now' => $now->get_timestamp());
        $page = AppContext::get_request()->get_getint('page', 1);
        $pagination = $this->get_pagination($condition, $parameters, $page);
        $result = PersistenceContext::get_querier()->select('SELECT news.*, member.*
		FROM ' . NewsSetup::$news_table . ' news
		LEFT JOIN ' . DB_TABLE_MEMBER . ' member ON member.user_id = news.author_user_id
		' . $condition . '
		ORDER BY top_list_enabled DESC, news.creation_date DESC
		LIMIT :number_items_per_page OFFSET :display_from', array_merge($parameters, array('number_items_per_page' => $pagination->get_number_items_per_page(), 'display_from' => $pagination->get_display_from())));
        $number_columns_display_news = $news_config->get_number_columns_display_news();
        $this->tpl->put_all(array('C_DISPLAY_BLOCK_TYPE' => $news_config->get_display_type() == NewsConfig::DISPLAY_BLOCK, 'C_DISPLAY_LIST_TYPE' => $news_config->get_display_type() == NewsConfig::DISPLAY_LIST, 'C_DISPLAY_CONDENSED_CONTENT' => $news_config->get_display_condensed_enabled(), 'C_COMMENTS_ENABLED' => $news_config->get_comments_enabled(), 'C_NEWS_NO_AVAILABLE' => $result->get_rows_count() == 0, 'C_PENDING_NEWS' => true, 'C_PAGINATION' => $pagination->has_several_pages(), 'PAGINATION' => $pagination->display(), 'C_SEVERAL_COLUMNS' => $number_columns_display_news > 1, 'NUMBER_COLUMNS' => $number_columns_display_news));
        while ($row = $result->fetch()) {
            $news = new News();
            $news->set_properties($row);
            $this->tpl->assign_block_vars('news', $news->get_array_tpl_vars());
            $this->build_sources_view($news);
        }
        $result->dispose();
    }
开发者ID:AroundPBT,项目名称:PHPBoost,代码行数:27,代码来源:NewsDisplayPendingNewsController.class.php

示例8: startUserSession

 public function startUserSession($row)
 {
     $login_key = $_SESSION['login_key'];
     # Unset all session variable
     $_SESSION = array();
     # Destroy session
     session_destroy();
     # New session name
     session_name(SESS_NAME);
     # New session id
     session_id($login_key);
     # Start Session
     session_start();
     $ts = new Date();
     # Initialize session
     $_SESSION['start_ts'] = $ts->getTs();
     $_SESSION['start_ts_str'] = $ts->getDate();
     $_SESSION['auth_state'] = 'user';
     $_SESSION['user_id'] = $row['id'];
     $_SESSION['login_key'] = $login_key;
     # Destroy old User object
     $this->user->__destruct();
     # Initialize new User object
     $this->user = User::getInstance($_SESSION['user_id']);
 }
开发者ID:ryzhov,项目名称:ATS0,代码行数:25,代码来源:Session.php

示例9: getCMSFields

 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $createdDate = new Date();
     $createdDate->setValue($this->Created);
     $reviewer = $this->Member()->Name;
     $email = $this->Member()->Email;
     $star = "&#9733;";
     $emptyStar = "&#9734;";
     $fields->insertBefore(LiteralField::create('reviewer', '<p>Written by <strong>' . $this->getMemberDetails() . '</strong><br />' . $createdDate->Format('l F jS Y h:i:s A') . '</p>'), 'Title');
     $fields->insertBefore(CheckboxField::create('Approved'), 'Title');
     $starRatings = $this->StarRatings();
     foreach ($starRatings as $starRating) {
         $cat = $starRating->StarRatingCategory;
         $stars = str_repeat($star, $starRating->Rating);
         $ratingStars = $stars;
         $maxRating = $starRating->MaxRating - $starRating->Rating;
         $emptyStarRepeat = str_repeat($emptyStar, $maxRating);
         $emptyStars = $emptyStarRepeat;
         /* 4/5 Stars */
         $ratingInfo = $ratingStars . $emptyStars . ' (' . $starRating->Rating . ' of ' . $starRating->MaxRating . ' Stars)';
         $fields->insertBefore(ReadonlyField::create('rating_' . $cat, $cat, html_entity_decode($ratingInfo, ENT_COMPAT, 'UTF-8')), 'Title');
     }
     $fields->removeByName('StarRatings');
     $fields->removeByName('MemberID');
     $fields->removeByName('ProductID');
     return $fields;
 }
开发者ID:helpfulrobot,项目名称:clintlandrum-silverstripe-productreviews,代码行数:28,代码来源:ProductReview.php

示例10: testConvertingDateIntoString

 public function testConvertingDateIntoString()
 {
     $ts = mktime(12, 30, 0, 7, 4, 1983);
     $date = new Date($ts);
     $date->setFormat('d.m.Y H:i:s');
     return $this->assertEqual((string) $date, '04.07.1983 12:30:00');
 }
开发者ID:enyo,项目名称:rincewind,代码行数:7,代码来源:Date.stest.php

示例11: export

 /**
  * The method to generate a plugin-style report XLS from an already
  * prepared statistics page OA_Admin_Statistics_Common object.
  */
 function export()
 {
     // Prepare the report name
     // Get system navigation
     $oMenu = OA_Admin_Menu::singleton();
     // Get section by pageId
     $oCurrentSection = $oMenu->get($this->oStatsController->pageId);
     if ($oCurrentSection == null) {
         phpAds_Die($GLOBALS['strErrorOccurred'], 'Menu system error: <strong>' . OA_Permission::getAccountType(true) . '::' . htmlspecialchars($ID) . '</strong> not found for the current user');
     }
     // Get name
     $reportName = $oCurrentSection->getName();
     $this->_name = $reportName;
     // Prepare the output writer for generation
     $reportFileName = 'Exported Statistics - ' . $reportName;
     if (!empty($this->oStatsController->aDates['day_begin'])) {
         $oStartDate = new Date($this->oStatsController->aDates['day_begin']);
         $reportFileName .= ' from ' . $oStartDate->format($GLOBALS['date_format']);
     }
     if (!empty($this->oStatsController->aDates['day_end'])) {
         $oEndDate = new Date($this->oStatsController->aDates['day_end']);
         $reportFileName .= ' to ' . $oEndDate->format($GLOBALS['date_format']);
     }
     $reportFileName .= '.xls';
     $this->_oReportWriter->openWithFilename($reportFileName);
     // Get the header and data arrays from the same statistics controllers
     // that prepare stats for the user interface stats pages
     list($aHeaders, $aData) = $this->getHeadersAndDataFromStatsController(null, $this->oStatsController);
     // Add the worksheet
     $name = ucfirst($this->oStatsController->entity) . ' ' . ucfirst($this->oStatsController->breakdown);
     $this->createSubReport($reportName, $aHeaders, $aData);
     // Close the report writer and send the report to the user
     $this->_oReportWriter->closeAndSend();
 }
开发者ID:Spark-Eleven,项目名称:revive-adserver,代码行数:38,代码来源:Export.php

示例12: diff

 /** Diff two date objects. Only full units are returned */
 public static function diff(TimeInterval $interval, Date $date1, Date $date2) : int
 {
     if ($date1->getOffsetInSeconds() != $date2->getOffsetInSeconds()) {
         // Convert date2 to same timezone as date1. To work around PHP bug #45038,
         // not just take the timezone of date1, but construct a new one which will
         // have a timezone ID - which is required for this kind of computation.
         $tz = new TimeZone(timezone_name_from_abbr('', $date1->getOffsetInSeconds(), $date1->toString('I')));
         // Now, convert both dates to the same time (actually we only need to convert the
         // second one, as the first will remain in the same timezone)
         $date2 = $tz->translate($date2);
     }
     // Then cut off timezone, by setting both to GMT
     $date1 = DateUtil::setTimeZone($date1, new TimeZone('GMT'));
     $date2 = DateUtil::setTimeZone($date2, new TimeZone('GMT'));
     switch ($interval) {
         case TimeInterval::$YEAR:
             return -($date1->getYear() - $date2->getYear());
         case TimeInterval::$MONTH:
             return -(($date1->getYear() - $date2->getYear()) * 12 + ($date1->getMonth() - $date2->getMonth()));
         case TimeInterval::$DAY:
             return -(intval($date1->getTime() / 86400) - intval($date2->getTime() / 86400));
         case TimeInterval::$HOURS:
             return -(intval($date1->getTime() / 3600) - intval($date2->getTime() / 3600));
         case TimeInterval::$MINUTES:
             return -(intval($date1->getTime() / 60) - intval($date2->getTime() / 60));
         case TimeInterval::$SECONDS:
             return -($date1->getTime() - $date2->getTime());
     }
 }
开发者ID:xp-framework,项目名称:core,代码行数:30,代码来源:DateMath.class.php

示例13: get_search_request

 public function get_search_request($args)
 {
     $now = new Date();
     $authorized_categories = ArticlesService::get_authorized_categories(Category::ROOT_CATEGORY);
     $weight = isset($args['weight']) && is_numeric($args['weight']) ? $args['weight'] : 1;
     return "SELECT " . $args['id_search'] . " AS id_search,\n\t\t\tarticles.id AS id_content,\n\t\t\tarticles.title AS title,\n\t\t\t(2 * FT_SEARCH_RELEVANCE(articles.title, '" . $args['search'] . "') + (FT_SEARCH_RELEVANCE(articles.contents, '" . $args['search'] . "') +\n\t\t\tFT_SEARCH_RELEVANCE(articles.description, '" . $args['search'] . "')) / 2 ) / 3 * " . $weight . " AS relevance,\n\t\t\tCONCAT('" . PATH_TO_ROOT . "/articles/index.php?url=/', id_category, '-', IF(id_category != 0, cat.rewrited_name, 'root'), '/', articles.id, '-', articles.rewrited_title) AS link\n\t\t\tFROM " . ArticlesSetup::$articles_table . " articles\n\t\t\tLEFT JOIN " . ArticlesSetup::$articles_cats_table . " cat ON cat.id = articles.id_category\n\t\t\tWHERE ( FT_SEARCH(articles.title, '" . $args['search'] . "') OR FT_SEARCH(articles.contents, '" . $args['search'] . "') OR FT_SEARCH_RELEVANCE(articles.description, '" . $args['search'] . "') )\n\t\t\tAND id_category IN(" . implode(", ", $authorized_categories) . ")\n\t\t\tAND (published = 1 OR (published = 2 AND publishing_start_date < '" . $now->get_timestamp() . "' AND (publishing_end_date > '" . $now->get_timestamp() . "' OR publishing_end_date = 0)))\n\t\t\tORDER BY relevance DESC\n\t\t\tLIMIT 100 OFFSET 0";
 }
开发者ID:AroundPBT,项目名称:PHPBoost,代码行数:7,代码来源:ArticlesSearchable.class.php

示例14: build_view

    public function build_view()
    {
        $now = new Date();
        $authorized_categories = NewsService::get_authorized_categories(Category::ROOT_CATEGORY);
        $news_config = NewsConfig::load();
        $condition = 'WHERE relation.id_keyword = :id_keyword
		AND id_category IN :authorized_categories
		AND (approbation_type = 1 OR (approbation_type = 2 AND start_date < :timestamp_now AND (end_date > :timestamp_now OR end_date = 0)))';
        $parameters = array('id_keyword' => $this->get_keyword()->get_id(), 'authorized_categories' => $authorized_categories, 'timestamp_now' => $now->get_timestamp());
        $page = AppContext::get_request()->get_getint('page', 1);
        $pagination = $this->get_pagination($condition, $parameters, $page);
        $result = PersistenceContext::get_querier()->select('SELECT news.*, member.*
		FROM ' . NewsSetup::$news_table . ' news
		LEFT JOIN ' . DB_TABLE_KEYWORDS_RELATIONS . ' relation ON relation.module_id = \'news\' AND relation.id_in_module = news.id 
		LEFT JOIN ' . DB_TABLE_MEMBER . ' member ON member.user_id = news.author_user_id
		' . $condition . '
		ORDER BY top_list_enabled DESC, news.creation_date DESC
		LIMIT :number_items_per_page OFFSET :display_from', array_merge($parameters, array('number_items_per_page' => $pagination->get_number_items_per_page(), 'display_from' => $pagination->get_display_from())));
        $number_columns_display_news = $news_config->get_number_columns_display_news();
        $this->tpl->put_all(array('C_DISPLAY_BLOCK_TYPE' => $news_config->get_display_type() == NewsConfig::DISPLAY_BLOCK, 'C_DISPLAY_LIST_TYPE' => $news_config->get_display_type() == NewsConfig::DISPLAY_LIST, 'C_DISPLAY_CONDENSED_CONTENT' => $news_config->get_display_condensed_enabled(), 'C_COMMENTS_ENABLED' => $news_config->get_comments_enabled(), 'C_NEWS_NO_AVAILABLE' => $result->get_rows_count() == 0, 'C_PAGINATION' => $pagination->has_several_pages(), 'PAGINATION' => $pagination->display(), 'C_SEVERAL_COLUMNS' => $number_columns_display_news > 1, 'NUMBER_COLUMNS' => $number_columns_display_news, 'CATEGORY_NAME' => $this->get_keyword()->get_name()));
        while ($row = $result->fetch()) {
            $news = new News();
            $news->set_properties($row);
            $this->tpl->assign_block_vars('news', array_merge($news->get_array_tpl_vars(), array('L_COMMENTS' => CommentsService::get_number_and_lang_comments('news', $row['id']), 'NUMBER_COM' => !empty($row['number_comments']) ? $row['number_comments'] : 0)));
            $this->build_sources_view($news);
        }
        $result->dispose();
    }
开发者ID:AroundPBT,项目名称:PHPBoost,代码行数:28,代码来源:NewsDisplayNewsTagController.class.php

示例15: 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;
 }
开发者ID:bmartinezteltek,项目名称:PuMuKIT2,代码行数:33,代码来源:EventRepository.php


注:本文中的Date类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。