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


PHP Timestamp::setYear方法代码示例

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


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

示例1: Articles

 /** 
  * calculates the array to display with the months
  *
  * @private
  */
 function _getMonths()
 {
     $articles = new Articles();
     $archiveStats = $articles->getNumberPostsPerMonthAdmin($this->_blogInfo->getId());
     if (!$archiveStats) {
         return array();
     }
     $result = array();
     $t = new Timestamp();
     $curyear = (int) $t->getYear();
     $curmonth = (int) $t->getMonth();
     $archiveDateFormat = $this->_locale->tr("archive_date_format");
     if ($archiveDateFormat == "archive_date_format") {
         $archiveDateFormat = "%B %Y";
     }
     foreach ($archiveStats as $yearName => $year) {
         foreach ($year as $monthName => $month) {
             // the next bit is so disgustingly ugly that I am ashamed of it...
             // what I'm trying to do here is that the getNumberPostsPerMonthAdmin() method
             // won't return the current month if there wasn't anything posted during it but
             // we still should show the current month even if there's nothing in it, because otherwise
             // when generating page where the posts are listed, it will end up saying "Date: All"
             // but no posts at all shown (it didn't have anything to show) This is a way of
             // "introducing" a month in the array without fucking it up. In fact, PHP *was*
             // indeed fucking it up... it didn't just want to keep the order! Oh well, it's a very
             // long and stupid story but we need this hack, ok? :)
             if ($archiveStats[$curyear][$curmonth] == "" && !$alreadyAdded) {
                 // there goes the dirty hack :P
                 if ($yearName == $curyear && $monthName < $curmonth) {
                     $t = new Timestamp();
                     $name = $this->_locale->formatDate($t, $archiveDateFormat);
                     $monthStr = array("name" => $name, "date" => $this->_locale->formatDate($t, "%Y%m"));
                     array_push($result, $monthStr);
                     $alreadyAdded = true;
                 }
             }
             // we can use the Timestamp class to help us with this...
             $t = new Timestamp("");
             $t->setYear($yearName);
             $t->setMonth($monthName);
             $name = $this->_locale->formatDate($t, $archiveDateFormat);
             $monthStr = array("name" => $name, "date" => $this->_locale->formatDate($t, "%Y%m"));
             array_push($result, $monthStr);
         }
     }
     return $result;
 }
开发者ID:BackupTheBerlios,项目名称:plogfr-svn,代码行数:52,代码来源:adminpostslistview.class.php

示例2: array

 /**
  * Fetches the stats for the archives
  *
  * @private
  */
 function _getArchives()
 {
     $archiveStats = $this->articles->getNumberPostsPerMonth($this->_blogInfo->getId());
     if ($archiveStats == '') {
         return false;
     }
     $links = array();
     $locale = $this->_blogInfo->getLocale();
     $urls = $this->_blogInfo->getBlogRequestGenerator();
     // format of dates used in the archive, but it defaults to '%B %Y' if none specified
     $archiveDateFormat = $locale->tr('archive_date_format');
     // need to check whether we got the same thing back, since that's the way Locale::tr() works instead of
     // returning an empty string
     if ($archiveDateFormat == "archive_date_format") {
         $archiveDateFormat = ARCHIVE_DEFAULT_DATE_FORMAT;
     }
     foreach ($archiveStats as $yearName => $year) {
         foreach ($year as $monthName => $month) {
             // we can use the Timestamp class to help us with this...
             $t = new Timestamp();
             $t->setYear($yearName);
             $t->setMonth($monthName);
             $archiveUrl = $urls->getArchiveLink($t->getYear() . $t->getMonth());
             $linkName = $locale->formatDate($t, $archiveDateFormat);
             $link = new ArchiveLink($linkName, '', $archiveUrl, $this->_blogInfo->getId(), 0, $month, 0);
             $links[] = $link;
         }
     }
     return $links;
 }
开发者ID:BackupTheBerlios,项目名称:plogfr-svn,代码行数:35,代码来源:blogview.class.php


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