當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DateHelper::timeSince方法代碼示例

本文整理匯總了PHP中DateHelper::timeSince方法的典型用法代碼示例。如果您正苦於以下問題:PHP DateHelper::timeSince方法的具體用法?PHP DateHelper::timeSince怎麽用?PHP DateHelper::timeSince使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DateHelper的用法示例。


在下文中一共展示了DateHelper::timeSince方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testTimeSince

 public function testTimeSince()
 {
     Localization::changeLocale('en_US');
     $minutes = 60;
     $hours = $minutes * 60;
     $days = $hours * 24;
     // time is in the future
     $future = time() + 7;
     $this->assertEquals($this->object->formatDate($future, false), $this->object->timeSince($future));
     // time is now
     $this->assertEquals('0 seconds', $this->object->timeSince(time()));
     // time is in the past (less that one year)
     $this->assertEquals('7 seconds', $this->object->timeSince(time() - 7));
     $this->assertEquals('3 minutes', $this->object->timeSince(time() - (3 * $minutes + 13)));
     $this->assertEquals('3 minutes, 13 seconds', $this->object->timeSince(time() - (3 * $minutes + 13), true));
     $this->assertEquals('4 hours', $this->object->timeSince(time() - (4 * $hours + 2 * $minutes)));
     $this->assertEquals('4 hours, 1 minute', $this->object->timeSince(time() - (4 * $hours + 1 * $minutes), true));
     $this->assertEquals('1 day', $this->object->timeSince(time() - (1 * $days + 1 * $minutes)));
     $this->assertEquals('2 days, 2 hours', $this->object->timeSince(time() - (2 * $days + 2 * $hours), true));
     $this->assertEquals('145 days', $this->object->timeSince(time() - 145 * $days));
     // time is in the past (more that one year)
     $this->assertEquals($this->object->formatDate(time() - 367 * $days, false), $this->object->timeSince(time() - 367 * $days));
 }
開發者ID:ojalehto,項目名稱:concrete5-legacy,代碼行數:23,代碼來源:DateHelperTest.php

示例2: testTimeSince

 public function testTimeSince()
 {
     Localization::changeLocale("en_US");
     $minutes = 60;
     $hours = $minutes * 60;
     $days = $hours * 24;
     // time is in the future
     $future = time() + 7;
     $this->assertEquals($this->object->formatDate($future), $this->object->timeSince($future));
     // time is now
     $this->assertEquals("0 seconds", $this->object->timeSince(time()));
     // time is in the past
     $this->assertEquals("7 seconds", $this->object->timeSince(time() - 7));
     $this->assertEquals("3 minutes", $this->object->timeSince(time() - (3 * $minutes + 13)));
     $this->assertEquals("3 minutes, 13 seconds", $this->object->timeSince(time() - (3 * $minutes + 13), 1));
     $this->assertEquals("4 hours", $this->object->timeSince(time() - (4 * $hours + 2 * $minutes)));
     $this->assertEquals("4 hours, 1 minute", $this->object->timeSince(time() - (4 * $hours + 1 * $minutes), 1));
     $this->assertEquals("1 day", $this->object->timeSince(time() - (1 * $days + 1 * $minutes)));
     $this->assertEquals("2 days, 2 hours", $this->object->timeSince(time() - (2 * $days + 2 * $hours), 1));
     $this->assertEquals('145 days', $this->object->timeSince(time() - 145 * $days));
     $this->assertEquals($this->object->formatDate(time() - 367 * $days), $this->object->timeSince(time() - 367 * $days));
 }
開發者ID:ceko,項目名稱:concrete5-1,代碼行數:22,代碼來源:DateHelperTest.php


注:本文中的DateHelper::timeSince方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。