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


PHP Timestamp::getMonth方法代码示例

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


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

示例1: getNumberOfPostsThisMonth

 function getNumberOfPostsThisMonth()
 {
     $today = new Timestamp();
     $monthTimestamp = $today->getYear() . $today->getMonth();
     $query = "SELECT COUNT(*) AS total FROM " . $this->getPrefix() . "articles" . " WHERE date LIKE '{$monthTimestamp}%' AND status = 1";
     return $this->getTotalFromQuery($query);
 }
开发者ID:BackupTheBerlios,项目名称:plogfr-svn,代码行数:7,代码来源:sitestatistics.class.php

示例2: getArchiveLink

 /**
  * generates an archive link given a date. 
  *
  * @param date A Timestamp object
  * @return A valid archive link
  */
 function getArchiveLink($date)
 {
     $archiveLinkFormat = $this->_config->getValue('archive_link_format');
     $ownerInfo = $this->_blogInfo->getOwnerInfo();
     // this is quite a dirty one but it works...
     $newDate = $date;
     if (strlen($date) == 6) {
         $newDate = $date . "00000000";
     }
     if (strlen($date) == 8) {
         $newDate = $date . "000000";
     }
     $t = new Timestamp($newDate);
     $params = array("{year}" => $t->getYear(), "{month}" => $t->getMonth(), "{blogname}" => $this->_blogInfo->getMangledBlog(), "{blogowner}" => $ownerInfo->getUsername(), "{blogid}" => $this->_blogInfo->getId());
     if (strlen($date) == 6) {
         $params["{day}"] = "";
     } else {
         $day = $t->getDay();
         if ($day < 10) {
             $day = "0" . $day;
         }
         $params["{day}"] = $day;
     }
     $archiveLink = $this->getBaseUrl() . $this->_replaceTags($archiveLinkFormat, $params);
     return $archiveLink;
 }
开发者ID:BackupTheBerlios,项目名称:plogfr-svn,代码行数:32,代码来源:customrequestgenerator.class.php

示例3: testNonEpoch

 public function testNonEpoch()
 {
     $future = '4683-03-04';
     $after = new Timestamp($future);
     $this->assertEquals('04', $after->getDay());
     $this->assertEquals('03', $after->getMonth());
     $this->assertEquals('4683', $after->getYear());
     $past = '1234-04-03';
     $before = new Timestamp($past);
     $this->assertEquals('03', $before->getDay());
     $this->assertEquals('04', $before->getMonth());
     $this->assertEquals('1234', $before->getYear());
     $this->assertFalse($after->equals($before));
     $this->assertEquals($future, $after->toDate());
     $this->assertEquals($past, $before->toDate());
     $time = ' 00:00.00';
     $this->assertEquals($future . $time, $after->toDateTime());
     $this->assertEquals($past . $time, $before->toDateTime());
     $past = '1-04-03';
     $before = new Timestamp($past);
     $this->assertEquals('03', $before->getDay());
     $this->assertEquals('04', $before->getMonth());
     $this->assertEquals(substr(date('Y', time()), 0, 2) . '01', $before->getYear());
     $past = '14-01-02';
     $before = new Timestamp($past);
     $this->assertEquals('02', $before->getDay());
     $this->assertEquals('01', $before->getMonth());
     $this->assertEquals(substr(date('Y', time()), 0, 2) . '14', $before->getYear());
     $past = '113-01-02';
     $before = new Timestamp($past);
     $this->assertEquals('02', $before->getDay());
     $this->assertEquals('01', $before->getMonth());
     $this->assertEquals('0113', $before->getYear());
 }
开发者ID:onphp-framework,项目名称:onphp-framework,代码行数:34,代码来源:TimestampTest.class.php

示例4: 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

示例5: testNonEpoch

 public function testNonEpoch()
 {
     $future = '4683-03-04';
     $after = new Timestamp($future);
     $this->assertEquals($after->getDay(), '04');
     $this->assertEquals($after->getMonth(), '03');
     $this->assertEquals($after->getYear(), '4683');
     $past = '1234-04-03';
     $before = new Timestamp($past);
     $this->assertEquals($before->getDay(), '03');
     $this->assertEquals($before->getMonth(), '04');
     $this->assertEquals($before->getYear(), '1234');
     $this->assertFalse($after->equals($before));
     $this->assertEquals($future, $after->toDate());
     $this->assertEquals($past, $before->toDate());
     $time = ' 00:00.00';
     $this->assertEquals($future . $time, $after->toDateTime());
     $this->assertEquals($past . $time, $before->toDateTime());
 }
开发者ID:rero26,项目名称:onphp-framework,代码行数:19,代码来源:TimestampTest.class.php

示例6: getNumberPostsPerDay

 /**
  * The same as the one above but for just one month
  *
  * @param blogId The identifier of the blog from which we'd like to calculate this
  * @param year Year
  * @param month Month from which we'd like to calculate this
  * @return An associative array where the index is the day of the month and the value
  * is the number of posts made that day.
  */
 function getNumberPostsPerDay($blogId, $year = null, $month = null)
 {
     // if month and/or year are empty, get the current ones
     if ($year == null) {
         $t = new Timestamp();
         $year = $t->getYear();
     }
     if ($month == null) {
         $t = new Timestamp();
         $month = $t->getMonth();
     }
     // another long sql query :) the id and date fields are there just in case we need to debug
     // but they're not included in the resulting array
     // $blogs = new Blogs();
     $blogSettings = $this->blogs->getBlogSettings($blogId);
     // consider the time difference
     $timeDifference = $blogSettings->getValue("time_offset");
     $SecondsDiff = $timeDifference * 3600;
     // check whether we're supposed to show posts that happen in the future or not
     if ($blogSettings->getValue("show_future_posts_in_calendar")) {
         $numPostsPerDayQuery = "SELECT COUNT(*) AS 'count', DAYOFMONTH(FROM_UNIXTIME(UNIX_TIMESTAMP(date) + {$SecondsDiff})) AS 'day', id AS 'id', date AS 'date' FROM " . $this->getPrefix() . "articles WHERE status = 1 AND blog_id = " . $blogId . " AND MONTH(FROM_UNIXTIME(UNIX_TIMESTAMP(date) + {$SecondsDiff})) = " . $month . " AND YEAR(FROM_UNIXTIME(UNIX_TIMESTAMP(date) + {$SecondsDiff})) = " . $year . " GROUP BY DAYOFMONTH(FROM_UNIXTIME(UNIX_TIMESTAMP(date) + {$SecondsDiff}));";
     } else {
         $numPostsPerDayQuery = "SELECT COUNT(*) AS 'count', DAYOFMONTH(FROM_UNIXTIME(UNIX_TIMESTAMP(date) + {$SecondsDiff})) AS 'day', id AS 'id', date AS 'date' FROM " . $this->getPrefix() . "articles WHERE status = 1 AND blog_id = " . $blogId . " AND date <= NOW() AND MONTH(FROM_UNIXTIME(UNIX_TIMESTAMP(date) + {$SecondsDiff})) = " . $month . " AND YEAR(FROM_UNIXTIME(UNIX_TIMESTAMP(date) + {$SecondsDiff})) = " . $year . " GROUP BY DAYOFMONTH(FROM_UNIXTIME(UNIX_TIMESTAMP(date) + {$SecondsDiff}));";
     }
     $result = $this->Execute($numPostsPerDayQuery);
     if ($result == false) {
         return 0;
     }
     $postsPerDay = array();
     while ($row = $result->FetchRow()) {
         $postsPerDay[$row["day"]] = $row["count"];
     }
     $result->Close();
     return $postsPerDay;
 }
开发者ID:BackupTheBerlios,项目名称:plogfr-svn,代码行数:44,代码来源:articles.class.php

示例7: 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

示例8: checkDateParameter

 /**
  * Checks if there is at least a year and a month in the request
  */
 function checkDateParameter()
 {
     $date = $this->_request->getValue('Date');
     if ($date) {
         $year = substr($date, 0, 4);
         $month = substr($date, 4, 2);
         $day = substr($date, 6, 2);
     } else {
         $t = new Timestamp();
         $year = $t->getYear();
         $month = $t->getMonth();
         $day = $t->getDay();
     }
     $this->_session->setValue('Year', $year);
     $this->_session->setValue('Month', $month);
     $this->_session->setValue('Day', $day);
 }
开发者ID:BackupTheBerlios,项目名称:plogfr-svn,代码行数:20,代码来源:blogaction.class.php


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