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


PHP DateTime类代码示例

本文整理汇总了PHP中DateTime的典型用法代码示例。如果您正苦于以下问题:PHP DateTime类的具体用法?PHP DateTime怎么用?PHP DateTime使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: xSaveAction

 public function xSaveAction()
 {
     $this->request->defineParams(array('category' => array('type' => 'string'), 'name' => array('type' => 'string'), 'value' => array('type' => 'json')));
     $governance = new Scalr_Governance($this->getEnvironmentId());
     $category = $this->getParam('category');
     $name = $this->getParam('name');
     $value = $this->getParam('value');
     if ($category == Scalr_Governance::CATEGORY_GENERAL && $name == Scalr_Governance::GENERAL_LEASE) {
         $enabled = (bool) $value['limits']['enableDefaultLeaseDuration'];
         unset($value['limits']['enableDefaultLeaseDuration']);
         if (!$governance->isEnabled(Scalr_Governance::CATEGORY_GENERAL, Scalr_Governance::GENERAL_LEASE) && $value['enabled'] == 1 && $enabled) {
             $dt = new DateTime();
             $dt->add(new DateInterval('P' . $value['limits']['defaultLifePeriod'] . 'D'));
             $farms = $this->db->GetCol('SELECT id FROM farms WHERE env_id = ? AND status = ?', array($this->getEnvironmentId(), FARM_STATUS::RUNNING));
             foreach ($farms as $farmId) {
                 $farm = DBFarm::LoadByID($farmId);
                 $farm->SetSetting(DBFarm::SETTING_LEASE_STATUS, 'Active');
                 $farm->SetSetting(DBFarm::SETTING_LEASE_TERMINATE_DATE, $dt->format('Y-m-d H:i:s'));
                 $farm->SetSetting(DBFarm::SETTING_LEASE_NOTIFICATION_SEND, '');
                 $farm->SetSetting(DBFarm::SETTING_LEASE_EXTEND_CNT, 0);
             }
         }
     }
     $governance->setValue($category, $name, $value);
     $this->response->success('Successfully saved');
 }
开发者ID:rickb838,项目名称:scalr,代码行数:26,代码来源:Governance.php

示例2: __construct

 public function __construct()
 {
     $this->TaxAmount = 0.0;
     $dateTime = new DateTime();
     $dateTime->setDate(1900, 01, 01);
     $this->TaxDate = $dateTime->format("Y-m-d");
 }
开发者ID:shabirm,项目名称:avatax,代码行数:7,代码来源:TaxOverride.class.php

示例3: getLastSyncDate

 /**
  * @return \DateTime|null
  */
 public function getLastSyncDate()
 {
     $channel = $this->getChannel();
     $repository = $this->managerRegistry->getRepository('OroIntegrationBundle:Status');
     /**
      * @var Status $status
      */
     $status = $repository->findOneBy(['code' => Status::STATUS_COMPLETED, 'channel' => $channel, 'connector' => $this->getType()], ['date' => 'DESC']);
     $timezone = new \DateTimeZone('UTC');
     $date = new \DateTime('now', $timezone);
     $context = $this->getStepExecution()->getExecutionContext();
     $data = $context->get(ConnectorInterface::CONTEXT_CONNECTOR_DATA_KEY) ?: [];
     $context->put(ConnectorInterface::CONTEXT_CONNECTOR_DATA_KEY, array_merge($data, [self::LAST_SYNC_DATE_KEY => $date->format(\DateTime::ISO8601)]));
     if (!$status) {
         return null;
     }
     $data = $status->getData();
     if (empty($data)) {
         return null;
     }
     if (!empty($data[self::LAST_SYNC_DATE_KEY])) {
         return new \DateTime($data[self::LAST_SYNC_DATE_KEY], $timezone);
     }
     return null;
 }
开发者ID:aculvi,项目名称:OroCRMMailChimpBundle,代码行数:28,代码来源:AbstractMailChimpConnector.php

示例4: deletespecials

 public function deletespecials()
 {
     $products = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect(array('special_price', 'special_to_date', 'status'))->addAttributeToFilter('special_price', array('notnull' => true))->addAttributeToFilter('status', array('eq' => 1));
     $numbers = array();
     $now = new DateTime();
     $time = $now->getTimestamp();
     Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));
     foreach ($products as $product) {
         if ($time <= strtotime($product->getSpecialToDate()) && $product->getSpecialToDate() != "") {
             /* Stock Set Variante
             			$stockItem = Mage::getModel('cataloginventory/stock_item')->load($product->getId(), 'product_id');
             			$stockItem->setData('is_in_stock', 0);
             			$stockItem->setTypeId( $product->getTypeId() );
             			$stockItem->setQty(0);
             			$stockItem->save();
             			*/
             /* Deaktivierungsvariante */
             $product->setStatus(2);
             $product->getResource()->saveAttribute($product, 'status');
             $numbers[] = $product->getStatus();
             /* Ende */
         } else {
         }
     }
     return $numbers;
 }
开发者ID:jronatay,项目名称:ultimo-magento-jron,代码行数:26,代码来源:mageSOAPAdvanced.php

示例5: hour_module

function hour_module($module)
{
    global $DB, $USER;
    //in format HH:MM:SS (varchar)
    //Define lthe hours for misreservas.php
    $modules = $DB->get_record('bookingrooms_modules', array("id" => $module));
    $start = explode(":", $modules->hour_start);
    $end = explode(":", $modules->hour_end);
    $a = $start[0];
    $b = $start[1];
    $c = 00;
    //hour;minute;second
    $d = $end[0];
    $e = (int) $end[1];
    $f = 00;
    //hour;minute;second
    $minutes = str_replace(' ', '', $e);
    $ModuleStart = new DateTime();
    // Is left hour and minutes in 0 (midnigth)
    $ModuleStart->setTime($a, $b, 0);
    $ModuleEnd = new DateTime();
    // Is left hour and minutes in 0 (midnigth)
    $ModuleEnd->setTime($d, $e, 0);
    $hour = array($ModuleStart, $ModuloEnd);
    //var_dump($hour);
    return $hour;
    //returns $hour[start] y $hour[end]
}
开发者ID:avillarroelp,项目名称:bookingrooms,代码行数:28,代码来源:lib.php

示例6: aggregatedMethods

 public function aggregatedMethods()
 {
     $ts = 374390100;
     $dt = new \DateTime();
     $dt->setTimestamp($ts);
     return array(array('getCurrentUser', array(), new User()), array('setCurrentUser', array(new User()), null), array('hasAccess', array('module', 'function', new User()), array('limitations')), array('canUser', array('module', 'function', new User(), new Location()), false), array('beginTransaction', array(), true), array('commit', array(), true), array('rollback', array(), true), array('createDateTime', array($ts), $dt));
 }
开发者ID:Pixy,项目名称:ezpublish-kernel,代码行数:7,代码来源:RepositoryTest.php

示例7: validateDigest

 public function validateDigest($digest, $nonce, $created, $secret)
 {
     // Generate created Token time difference
     $now = new \DateTime('now', new \DateTimeZone('UTC'));
     $then = new \Datetime($created, new \DateTimeZone('UTC'));
     $diff = $now->diff($then, true);
     // Check created time is not in the future
     if (strtotime($created) > time()) {
         throw new AuthenticationException("Back to the future...");
     }
     // Validate timestamp is recent within 5 minutes
     $seconds = time() - strtotime($created);
     if ($seconds > 300) {
         throw new AuthenticationException('Expired timestamp.  Seconds: ' . $seconds);
     }
     // Validate nonce is unique within 5 minutes
     if (file_exists($this->cacheDir . '/' . $nonce) && file_get_contents($this->cacheDir . '/' . $nonce) + 300 > time()) {
         throw new NonceExpiredException('Previously used nonce detected');
     }
     if (!is_dir($this->cacheDir)) {
         mkdir($this->cacheDir, 0777, true);
     }
     file_put_contents($this->cacheDir . '/' . $nonce, time());
     // Validate Secret
     $expected = base64_encode(sha1(base64_decode($nonce) . $created . $secret, true));
     // Return TRUE if our newly-calculated digest is the same as the one provided in the validateDigest() call
     return $expected === $digest;
 }
开发者ID:raziel057,项目名称:angular-symfony,代码行数:28,代码来源:WsseProvider.php

示例8: insert_profiles

function insert_profiles($name, $birthday, $type, $tell, $comment)
{
    //db接続を確立
    $insert_db = connect2MySQL();
    //DBに全項目のある1レコードを登録するSQL
    $insert_sql = "INSERT INTO user_t(name,birthday,tell,type,comment,newDate)" . "VALUES(:name,:birthday,:tell,:type,:comment,:newDate)";
    //現在時をdatetime型で取得
    $datetime = new DateTime();
    $date = $datetime->format('Y-m-d H:i:s');
    //クエリとして用意
    $insert_query = $insert_db->prepare($insert_sql);
    //SQL文にセッションから受け取った値&現在時をバインド
    $insert_query->bindValue(':name', $name);
    $insert_query->bindValue(':birthday', $birthday);
    $insert_query->bindValue(':tell', $tell);
    $insert_query->bindValue(':type', $type);
    $insert_query->bindValue(':comment', $comment);
    $insert_query->bindValue(':newDate', $date);
    //SQLを実行
    try {
        $insert_query->execute();
    } catch (PDOException $e) {
        //接続オブジェクトを初期化することでDB接続を切断
        $insert_db = null;
        return $e->getMessage();
    }
    $insert_db = null;
    return null;
}
开发者ID:GEEKJOB-CAMP,项目名称:UserManagementSystem,代码行数:29,代码来源:dbaccesUtil.php

示例9: fetch_data

 public function fetch_data()
 {
     $this->ci =& get_instance();
     $this->ci->load->model('my_gofundme_model');
     $my_gofundme = $this->ci->my_gofundme_model->get_info();
     //calculate time interval
     $last_fetched = new DateTime($my_gofundme['last_fetched']);
     $now = new DateTime('now');
     $diff = $now->diff($last_fetched);
     $interval = ($diff->d * 24 + $diff->h) * 60 + $diff->i;
     //print_r($diff);
     //fetch if over interval minutes since last time
     if ($interval >= $my_gofundme['interval']) {
         $html = $this->getHTML(trim($my_gofundme['url']), 5);
         if ($html != false && !empty($html)) {
             preg_match('/Raised by\\s*<span>(.*)<\\/span>\\s*people/i', $html, $match);
             $my_gofundme['num_donations'] = $match[1];
             preg_match('/<\\/span>(.*)<span class="of">/i', $html, $match);
             $my_gofundme['raised'] = $match[1];
             //echo 'num_donations = ' . $my_gofundme['num_donations'] . '</br>';
             //echo 'raised = ' . $my_gofundme['raised'] . '</br>';
         }
         //calculate days to go
         $now = new DateTime('now');
         $interval = $now->diff(new DateTime($my_gofundme['end_date']));
         $my_gofundme['days_to_go'] = $interval->days;
         $this->ci->my_gofundme_model->update_info($my_gofundme);
     }
     return array('my_gofundme_url' => $my_gofundme['url'], 'num_donations' => $my_gofundme['num_donations'], 'raised' => $my_gofundme['raised'], 'goal' => $my_gofundme['goal'], 'days_to_go' => $my_gofundme['days_to_go']);
 }
开发者ID:centaurustech,项目名称:fundme-1,代码行数:30,代码来源:My_gofundme.php

示例10: sec2time

 /**
  * Convert seconds into human readeble time
  * @param int $seconds 
  * @return string
  */
 public static function sec2time($seconds)
 {
     $sec = intval($seconds);
     $dtF = new \DateTime("@0");
     $dtT = new \DateTime("@{$sec}");
     return $dtF->diff($dtT)->format('%a days, %h hours, %i minutes and %s seconds');
 }
开发者ID:Repkit,项目名称:demo-fastroute,代码行数:12,代码来源:Time.php

示例11: setFilteredResults

 function setFilteredResults()
 {
     $this->queryBuilder = $this->doctrine->getEntityManager()->createQueryBuilder();
     $this->queryBuilder->select('a, b')->from('HelperBundle:FeedbackMessage', 'a')->leftJoin('a.country', 'b');
     if ($this->queryParams['keyword']) {
         $this->queryBuilder->where('a.name LIKE :searchKey OR a.emailAddress LIKE :searchKey OR a.message LIKE :searchKey');
         $this->queryBuilder->setParameter('searchKey', '%' . $this->queryParams['keyword'] . '%');
     }
     if ($this->queryParams['country'] != self::FILTER_KEY_ALL) {
         $this->queryBuilder->where('a.country = :country');
         $this->queryBuilder->setParameter('country', $this->queryParams['country']);
     }
     if ($this->queryParams['dateCreated']) {
         list($year, $month, $day) = explode('-', $this->queryParams['dateCreated']);
         $dateFrom = new \DateTime();
         $dateFrom->setDate($year, $month, $day);
         $dateFrom->setTime('00', '00', '00');
         $dateTo = clone $dateFrom;
         $dateTo->setTime('23', '59', '59');
         $this->queryBuilder->andWhere('a.dateCreated >= :dateFrom AND a.dateCreated <= :dateTo');
         $this->queryBuilder->setParameter('dateFrom', $dateFrom)->setParameter('dateTo', $dateTo);
     }
     $sortBy = $this->sortBy ? $this->sortBy : 'dateCreated';
     $sort = "a.{$sortBy} " . $this->sortOrder;
     $this->queryBuilder->add('orderBy', $sort);
     $this->pagerAdapter->setQueryBuilder($this->queryBuilder);
     //echo $this->queryBuilder->getQuery()->getSQL(); exit;
     $this->filteredResult = $this->pager->getResults();
 }
开发者ID:TMBaay,项目名称:MEDTrip---Healthcareabroad,代码行数:29,代码来源:FeedbackListFilter.php

示例12: getLatestAwardExpectInfo

 /**
 * 获取最新采集期号信息
 *
 * @return array(
               'expect' => '141106036',
               'opentime' => 1402143035
           )
 */
 public function getLatestAwardExpectInfo()
 {
     //获取开始统计日期到现在时间的天数
     $startCountDatetime = new \DateTime($this->getStartCountDate());
     $nowDatetime = new \DateTime(date('Y-m-d', $this->nowTimestamp));
     $datetimeDiff = $startCountDatetime->diff($nowDatetime);
     $diffDay = intval($datetimeDiff->format('%a'));
     //今天第一期期号
     $expect = $this->getStartCountExpect() + $diffDay * $this->getDailyOpenExpectNum();
     $opentime = 0;
     foreach ($this->getAwardTimeInfo() as $item) {
         $start = strtotime($item['start'], $this->nowTimestamp);
         $end = strtotime($item['end'], $this->nowTimestamp);
         for ($i = $start; $i <= $end; $i += $item['interval']) {
             $deviation = $this->nowTimestamp - $i;
             $minDeviation = isset($item['minDeviation']) ? $item['minDeviation'] : 0;
             $maxDeviation = isset($item['maxDeviation']) ? $item['maxDeviation'] : 30;
             if ($deviation >= $minDeviation && $deviation <= $maxDeviation) {
                 $opentime = $i;
                 break 2;
             }
             $expect++;
         }
     }
     if (!$opentime) {
         return false;
     }
     return array('expect' => $this->formatExpect($expect, $opentime), 'opentime' => $opentime);
 }
开发者ID:sdgdsffdsfff,项目名称:Pari,代码行数:37,代码来源:Customkeno2.php

示例13: formatDateTime

 /**
  * Format date and time.
  * @param DateTime $date date to be formatted
  * @return string formatted date and time
  */
 public static function formatDateTime(DateTime $date = null)
 {
     if ($date === null) {
         return '';
     }
     return $date->format('m/d/Y H:i');
 }
开发者ID:jhonochoa,项目名称:larabel,代码行数:12,代码来源:Utils.php

示例14: discussionController_beforeCommentDisplay_handler

 public function discussionController_beforeCommentDisplay_handler($sender, $args)
 {
     // Find the previous comment.
     if (!$this->previous) {
         $this->previous = $args['Discussion'];
         if ($sender->data('Page', 1) != 1) {
             $this->previous = $sender->CommentModel->get($sender->DiscussionID, 1, $sender->Offset - 1)->firstRow();
         }
     }
     // Calculate the date difference.
     $date = new DateTime($args['Comment']->DateInserted);
     $gap = $date->diff(new DateTime($this->previous->DateInserted))->days;
     $this->previous = $args['Comment'];
     if ($gap < c('TimeGap.MinDays', 7) - 1) {
         return;
     } elseif ($gap < 30) {
         $gap = sprintf(t('%s days later'), (int) $gap);
         $class = 'Days';
     } elseif ($gap < 60) {
         $gap = t('1 month later');
         $class = 'Month';
     } elseif ($gap < 365) {
         $gap = sprintf(t('%s months later'), (int) ($gap / 30));
         $class = 'Months';
     } elseif ($gap < 720) {
         $gap = t('1 year later');
         $class = 'Year';
     } else {
         $gap = sprintf(t('%s years later'), (int) ($gap / 365));
         $class = 'Years';
     }
     echo wrap($gap, 'li', ['class' => 'TimeGap ' . $class]);
 }
开发者ID:bleistivt,项目名称:timegap,代码行数:33,代码来源:class.timegap.plugin.php

示例15: db_array

 public function db_array()
 {
     $db_array = parent::db_array();
     $date = new DateTime();
     $db_array['client_note_date'] = $date->format('Y-m-d');
     return $db_array;
 }
开发者ID:rumahkecil,项目名称:fusioninvoice-1,代码行数:7,代码来源:mdl_client_notes.php


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