本文整理汇总了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;
}
示例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;
}
示例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();
}
示例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'));
}
示例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;
}
示例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');
}
示例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
}
示例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;
}
示例9: getDateArray
public function getDateArray()
{
if ($this->dateTime->getTimestamp() < 0) {
return [0, 0, 0];
}
return explode('-', $this->dateTime->format('Y-m-d'));
}
示例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));
}
示例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;
}
示例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;
}
}
}
示例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'));
}
示例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();
}
示例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;
}