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


PHP DateTime::getTimestamp方法代碼示例

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


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

示例1: getDateDelta

 public function getDateDelta($date)
 {
     $date = new DateTime($date);
     $diff = abs(time() - $date->getTimestamp());
     if ($diff < 10) {
         $message = "à l'instant";
     } else {
         if ($diff < 30) {
             $message = "il y a quelques secondes";
         } else {
             if ($diff < 60) {
                 $message = "il y a moins d'une minute";
             } else {
                 if (ceil($diff / 60) < 60) {
                     $message = "il y a " . ceil($diff / 60) . " minutes";
                 } else {
                     if (ceil($diff / 60 / 60) == 1) {
                         $message = "il y a environ une heure";
                     } else {
                         if (ceil($diff / 60 / 60) < 24) {
                             $message = "il y a " . ceil($diff / 60 / 60) . " heures";
                         } else {
                             // version linux :
                             // setlocale(LC_TIME, 'fr', 'fr_FR', 'fr_FR.ISO8859-1');
                             // version windows
                             setlocale(LC_TIME, 'french');
                             $message = utf8_encode(strftime('%#d %B, %H:%M', $date->getTimestamp()));
                         }
                     }
                 }
             }
         }
     }
     return $message;
 }
開發者ID:alexloic,項目名稱:abime,代碼行數:35,代碼來源:utils.php

示例2: getParams

 public function getParams()
 {
     $params = [];
     empty($this->dateMin) ?: ($params['date_min'] = $this->dateMin->getTimestamp());
     empty($this->dateMax) ?: ($params['date_max'] = $this->dateMax->getTimestamp());
     return $params;
 }
開發者ID:m1105,項目名稱:steam-api-php,代碼行數:7,代碼來源:GetScheduledLeagueGames.php

示例3: hasValidResetPasswordToken

 /**
  * Check if the user has a valid reset password token.
  *
  * @return bool
  */
 public function hasValidResetPasswordToken()
 {
     if ($this->resetPasswordTokenValidUntil == null) {
         return false;
     }
     return $this->resetPasswordTokenValidUntil->getTimestamp() > time();
 }
開發者ID:sandstorm,項目名稱:usermanagement,代碼行數:12,代碼來源:ResetPasswordFlow.php

示例4: testFormatTime

 public function testFormatTime()
 {
     $this->assertEquals($this->_dateTime->format(self::TIME_FORMAT_SHORT), $this->_helper->formatTime());
     $this->assertEquals($this->_dateTime->format(self::DATETIME_FORMAT_SHORT), $this->_helper->formatTime(null, 'short', true));
     $zendDate = new Zend_Date($this->_dateTime->getTimestamp());
     $this->assertEquals($zendDate->toString(self::TIME_FORMAT_SHORT_ISO), $this->_helper->formatTime($zendDate, 'short'));
 }
開發者ID:relue,項目名稱:magento2,代碼行數:7,代碼來源:DataTest.php

示例5: file_load

function file_load($type = 'metar')
{
    $remote_file = 'http://weather.aero/dataserver1_5/cache/' . $type . 's.cache.xml.gz';
    $local_file = $type . '.xml';
    $dt = NULL;
    if (file_exists($local_file)) {
        $h = get_headers($remote_file, 1);
        if (!(strstr($h[0], '200') === FALSE)) {
            $dt = new \DateTime($h['Last-Modified']);
            if ($dt->getTimestamp() - filemtime($local_file) < 300) {
                echo "Remote : " . $dt->getTimestamp() . " VS Local: " . filemtime($local_file) . " = " . ($dt->getTimestamp() - filemtime($local_file)) . "<br>";
                $xml = simplexml_load_file($local_file);
            } else {
                echo "Updating local file";
                $data = file_get_contents('compress.zlib://' . $remote_file);
                if (file_put_contents($local_file, $data)) {
                    $xml = simplexml_load_file($local_file);
                }
            }
            //echo "R - ".$dt->getTimestamp()." - "
            //.$dt->format('F d Y H:i:s')."<br/>";
        }
    } else {
        $data = file_get_contents('compress.zlib://' . $remote_file);
        if (file_put_contents($local_file, $data)) {
            $xml = simplexml_load_file($local_file);
        }
    }
    return $xml;
}
開發者ID:JohnieWalker,項目名稱:WXMonitor,代碼行數:30,代碼來源:datafetcher.php

示例6: test_StoreAnomaly_RetrieveGroupedAndSortedByNofAnomalies

 public function test_StoreAnomaly_RetrieveGroupedAndSortedByNofAnomalies()
 {
     /* This tries to test something that's a bit difficult to test.
      * The anomalies should be retrieved in sorted order from highest number of anomalies to lowest,
      * and contain all the anomalies for each group.
      *
      * We don't test limit and minCount here
      */
     $start = new DateTime('-5 minutes');
     $end = new DateTime('now');
     // Group 1
     $this->conn->col('anomalies')->insert(['nid' => '1', 'sid' => '1', 'predicted' => 30, 'actual' => 70, 'mongodate' => new MongoDate($start->getTimestamp())]);
     $this->conn->col('anomalies')->insert(['nid' => '1', 'sid' => '1', 'predicted' => 40, 'actual' => 80, 'mongodate' => new MongoDate($end->getTimestamp())]);
     $this->conn->col('anomalies')->insert(['nid' => '1', 'sid' => '1', 'predicted' => 45, 'actual' => 85, 'mongodate' => new MongoDate($end->getTimestamp())]);
     // Group 2
     $this->conn->col('anomalies')->insert(['nid' => '2', 'sid' => '1', 'predicted' => 50, 'actual' => 90, 'mongodate' => new MongoDate($start->getTimestamp())]);
     // Group 3
     $this->conn->col('anomalies')->insert(['nid' => '2', 'sid' => '2', 'predicted' => 60, 'actual' => 100, 'mongodate' => new MongoDate($start->getTimestamp())]);
     $this->conn->col('anomalies')->insert(['nid' => '2', 'sid' => '2', 'predicted' => 60, 'actual' => 100, 'mongodate' => new MongoDate($end->getTimestamp())]);
     $pipeline = new Pipeline();
     $pipelineFactory = new Factory($this->conn);
     $sequence = $pipelineFactory->createAnomalyAction($start, $end, ['1', '2'], ['1', '2'], 1, 3);
     $res = $pipeline->run($sequence);
     $this->assertEquals(3, count($res), 'Expected number of groups were wrong');
     $this->assertEquals(3, count($res[0]['anomalies']), 'Expected number of anomalies in grp1 were wrong');
     $this->assertEquals(2, count($res[1]['anomalies']), 'Expected number of anomalies in grp3 were wrong');
     $this->assertEquals(1, count($res[2]['anomalies']), 'Expected number of anomalies in grp2 were wrong');
 }
開發者ID:magnusjt,項目名稱:mongotd,代碼行數:28,代碼來源:AnomalyRetrievalTest.php

示例7: DateTimeZone

    function render_field($field)
    {
        /*
         *  Create a select dropdown with all available timezones
         */
        $utc = new DateTimeZone('UTC');
        $dt = new DateTime('now', $utc);
        ?>
        <select name="<?php 
        echo esc_attr($field['name']);
        ?>
">
            <?php 
        foreach (\DateTimeZone::listIdentifiers() as $tz) {
            $current_tz = new \DateTimeZone($tz);
            $transition = $current_tz->getTransitions($dt->getTimestamp(), $dt->getTimestamp());
            $abbr = $transition[0]['abbr'];
            $is_selected = trim($field['value']) === trim($tz) ? ' selected="selected"' : '';
            ?>
                <option value="<?php 
            echo $tz;
            ?>
"<?php 
            echo $is_selected;
            ?>
><?php 
            echo $tz . ' (' . $abbr . ')';
            ?>
</option>
            <?php 
        }
        ?>
        </select>
    <?php 
    }
開發者ID:Ricardo-Diaz,項目名稱:acf-timezone-picker,代碼行數:35,代碼來源:acf-timezone_picker-v5.php

示例8: documentProcessing

 private function documentProcessing($feed, $count, $date)
 {
     $news = array();
     $idx = 0;
     foreach ($feed->channel->item as $new) {
         if ($idx < $count) {
             $pubDate = new DateTime($new->pubDate);
             if ($date && $pubDate->getTimestamp() <= $date) {
                 continue;
             }
             $doc = new DOMDocument();
             @$doc->loadHTML($new->description);
             //Obtenemos las imágenes contenidas en las descripción.
             $images = $doc->getElementsByTagName('img');
             if ($images->length > 0) {
                 $poster = array();
                 foreach ($images as $image) {
                     $alt = $image->getAttribute('alt');
                     $src = $image->getAttribute('src');
                     $title = $image->getAttribute('title');
                     array_push($poster, array("alt" => $alt, "src" => $src, "title" => $title));
                 }
                 array_push($news, array("posters" => $poster, "title" => $new->title, "link" => $new->link, "date" => $pubDate->getTimestamp(), "desc" => $new->description));
                 $idx++;
             }
         } else {
             break;
         }
     }
     return $news;
 }
開發者ID:sergio11,項目名稱:teVeo,代碼行數:31,代碼來源:newsController.php

示例9: getDateArray

 public function getDateArray()
 {
     if ($this->dateTime->getTimestamp() < 0) {
         return [0, 0, 0];
     }
     return explode('-', $this->dateTime->format('Y-m-d'));
 }
開發者ID:trejjam,項目名稱:utils,代碼行數:7,代碼來源:DateTimeModification.php

示例10: formatProvider

 /**
  * A data provider for testFormat method.
  */
 public function formatProvider()
 {
     $now = new \DateTime();
     $format = "%H:%M %d-%m-%Y";
     $expected = strftime($format, $now->getTimestamp());
     return array(array($now, $format, $expected), array($now->getTimestamp(), $format, $expected), array((string) $now->getTimestamp(), $format, $expected));
 }
開發者ID:mezaof,項目名稱:handlebars.php-helpers,代碼行數:10,代碼來源:FormatDateHelperTest.php

示例11: getWeather

function getWeather($loc, $units = 'metric', $lang = 'en', $appid = '', $cachetime = 0)
{
    $url = "http://api.openweathermap.org/data/2.5/weather?q=" . $loc . "&appid=" . $appid . "&lang=" . $lang . "&units=" . $units . "&mode=xml";
    $cached = Cache::get('curweather' . md5($url));
    $now = new DateTime();
    if (!is_null($cached)) {
        $cdate = get_pconfig(local_user(), 'curweather', 'last');
        $cached = unserialize($cached);
        if ($cdate + $cachetime > $now->getTimestamp()) {
            return $cached;
        }
    }
    try {
        $res = new SimpleXMLElement(fetch_url($url));
    } catch (Exception $e) {
        info(t('Error fetching weather data.\\nError was: ' . $e->getMessage()));
        return false;
    }
    if ((string) $res->temperature['unit'] === 'metric') {
        $tunit = '°C';
        $wunit = 'm/s';
    } else {
        $tunit = '°F';
        $wunit = 'mph';
    }
    if (trim((string) $res->weather['value']) == trim((string) $res->clouds['name'])) {
        $desc = (string) $res->clouds['name'];
    } else {
        $desc = (string) $res->weather['value'] . ', ' . (string) $res->clouds['name'];
    }
    $r = array('city' => (string) $res->city['name'][0], 'country' => (string) $res->city->country[0], 'lat' => (string) $res->city->coord['lat'], 'lon' => (string) $res->city->coord['lon'], 'temperature' => (string) $res->temperature['value'][0] . $tunit, 'pressure' => (string) $res->pressure['value'] . (string) $res->pressure['unit'], 'humidity' => (string) $res->humidity['value'] . (string) $res->humidity['unit'], 'descripion' => $desc, 'wind' => (string) $res->wind->speed['name'] . ' (' . (string) $res->wind->speed['value'] . $wunit . ')', 'update' => (string) $res->lastupdate['value'], 'icon' => (string) $res->weather['icon']);
    set_pconfig(local_user(), 'curweather', 'last', $now->getTimestamp());
    Cache::set('curweather' . md5($url), serialize($r), CACHE_HOUR);
    return $r;
}
開發者ID:ZerGabriel,項目名稱:friendica-addons,代碼行數:35,代碼來源:curweather.php

示例12: DiffIn

 /**
  * Gets the time difference, but always returns it in a certain format
  * @param string $format The format, could be one of these: 
  * 'seconds', 'minutes', 'hours', 'days', 'months', 'years'.
  * 
  * @return string
  */
 public function DiffIn($format = 'default')
 {
     if ($this->owner->value) {
         $now = new DateTime();
         $timestamp = strtotime($this->owner->value);
         $value = new DateTime('@' . $timestamp);
         $diff = $value->diff($now);
         switch ($format) {
             case "seconds":
                 return abs($value->getTimestamp() - $now->getTimestamp());
                 break;
             case "minutes":
                 return abs(round(($value->getTimestamp() - $now->getTimestamp()) / 60));
                 break;
             case "hours":
                 return abs(round(($value->getTimestamp() - $now->getTimestamp()) / 60 / 60));
                 break;
             case "days":
                 return abs(round(($value->getTimestamp() - $now->getTimestamp()) / 60 / 60 / 24));
                 break;
             case "months":
                 return $diff->format('%m') + $diff->format('%y') * 12;
                 break;
             case "years":
                 return $diff->format('%y');
                 break;
             default:
                 return $diff;
                 break;
         }
     }
 }
開發者ID:andrelohmann,項目名稱:silverstripe-extended-date,代碼行數:39,代碼來源:ExtendedDate.php

示例13: testSpecifiedTimeZone

 public function testSpecifiedTimeZone()
 {
     $util = new DateTimeUtil(new \DateTimeZone('Asia/Singapore'));
     $dateTime = $util->createDateTimeByUnixTime($this->timestamp->getTimestamp());
     $this->assertEquals($this->timestamp, $dateTime);
     $this->assertEquals('+0800', $dateTime->format('O'));
 }
開發者ID:matsubo,項目名稱:spike-php,代碼行數:7,代碼來源:DateTimeUtilTest.php

示例14: isSumerSchedule

 /**
  * Check that today is between start & end
  * @return bool
  */
 public function isSumerSchedule()
 {
     $today = new \DateTime('today');
     $start = $this->getSumerScheduleStart();
     $end = $this->getSumerScheduleEnd();
     return $today->getTimestamp() >= $start->getTimestamp() && $today->getTimestamp() <= $end->getTimestamp();
 }
開發者ID:roberto-slopez,項目名稱:CYA,代碼行數:11,代碼來源:Agency.php

示例15: findNextBirthdays

 /**
  * @param Season $season
  * @return \AppBundle\Entity\Member[]
  */
 public function findNextBirthdays(Season $season)
 {
     // Period to scan
     $start = new \DateTime('-1 week');
     $stop = new \DateTime('+3 weeks');
     $builder = $this->createQueryBuilder('m')->innerJoin('m.memberships', 'ms')->andWhere('ms.season = :season')->setParameter('season', $season)->setParameter('start', $start->format('m-d'))->setParameter('stop', $stop->format('m-d'));
     if ($start->format('m') > $stop->format('m')) {
         $builder->andWhere('SUBSTRING( m.birthday, 6 ) >= :start OR SUBSTRING( m.birthday, 6 ) <= :stop');
     } else {
         $builder->andWhere('SUBSTRING( m.birthday, 6 ) BETWEEN :start AND :stop');
     }
     $members = $builder->getQuery()->getResult();
     // Sort by next birthday
     usort($members, function (Member $a, Member $b) use($stop) {
         $nextA = $a->getNextBirthday();
         $nextB = $b->getNextBirthday();
         if ($nextA->getTimestamp() > $stop->getTimestamp()) {
             $nextA->modify('-1 year');
         }
         if ($nextB->getTimestamp() > $stop->getTimestamp()) {
             $nextB->modify('-1 year');
         }
         return $nextA > $nextB;
     });
     return $members;
 }
開發者ID:thomasage,項目名稱:asso,代碼行數:30,代碼來源:MemberRepository.php


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