當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。