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


PHP DateTime::format方法代码示例

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


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

示例1: dateto

 public function dateto()
 {
     date_default_timezone_set('Asia/Bangkok');
     $now = new DateTime(null, new DateTimeZone('Asia/Bangkok'));
     $Y = $now->format('Y') + 543;
     return $now->format('d/m/') . $Y . $now->format(' H:i');
 }
开发者ID:mynameistecs51,项目名称:utsgs,代码行数:7,代码来源:template.php

示例2: getRates

 /**
  * Load rates by date
  *
  * @param ICurrency[] $currencies
  * @param \DateTime|null $date
  *
  * @return ICurrencyRate[]
  *
  * @throws NoRatesAvailableForDateException
  * @throws BadXMLQueryException
  */
 public function getRates($currencies, \DateTime $date = null)
 {
     $currencyCodes = [];
     foreach ($currencies as $currency) {
         $currencyCodes[] = $currency->getCode() . '=X';
     }
     if (null === $date) {
         $date = new \DateTime();
     }
     $queryData = ['q' => 'select * from yahoo.finance.historicaldata where symbol in ("' . implode('","', $currencyCodes) . '") and startDate = "' . $date->format('Y-m-d') . '" and endDate = "' . $date->format('Y-m-d') . '"', 'env' => 'store://datatables.org/alltableswithkeys'];
     $query = self::BASE_URL . '?' . http_build_query($queryData);
     $ratesXml = $this->xmlLoader->load($query);
     if (false === $ratesXml) {
         throw new BadXMLQueryException($query, $this);
     }
     if (0 === count($ratesXml->results->quote)) {
         throw new NoRatesAvailableForDateException($date, $this);
     }
     $rates = [];
     /** @var \SimpleXMLElement $rate */
     foreach ($ratesXml->results->quote as $quote) {
         $quote = (array) $quote;
         $code = (string) $quote['@attributes']['Symbol'];
         $code = str_replace('%3dX', '', $code);
         $rate = $quote['Close'];
         $rates[$code] = $this->currencyRateManager->getNewInstance($this->currencyManager->getCurrency($code), $this, $date, (double) $rate, 1);
     }
     return $rates;
 }
开发者ID:remedge,项目名称:redcode-currency-rate,代码行数:40,代码来源:YahooCurrencyRateProvider.php

示例3: val

 /**
  * 
  * function val - This function allows validate the date format and if it's true
  * return the same date if it's not throw and exception.
  * 
  * @param string $val 
  * @return string
  * @throws \SimplOn\DataValidationException
  */
 function val($val = null)
 {
     // if $val is defined and isn't null, start to verify the value
     if (isset($val) && $val) {
         $val = trim($val);
         //if $val is empty and is required then throw an exception.
         if (!$val && $this->required) {
             throw new \SimplOn\DataValidationException($this->validationDate);
         } else {
             try {
                 if (is_numeric($val)) {
                     $dateObj = new \DateTime();
                     $dateObj->setTimestamp($val);
                 } else {
                     $dateObj = new \DateTime($val);
                     // throw new \SimplOn\DataValidationException($this->isnotNumeric);
                 }
             } catch (\Exception $e) {
                 throw new \SimplOn\DataValidationException($this->validationDate);
             }
         }
         // $this->val save the date with format for database
         $this->val = $dateObj->format($this->dbFormat);
         // $this->viewVal save the the date with format to show in the view
         $this->viewVal = $dateObj->format($this->viewFormat);
     } else {
         return $this->val;
     }
 }
开发者ID:simplonphp,项目名称:simplonphp,代码行数:38,代码来源:Date.php

示例4: indexAction

 public function indexAction()
 {
     $em = $this->EntityPlugin()->getEntityManager();
     $auth = $this->getServiceLocator()->get('Zend\\Authentication\\AuthenticationService');
     $user = $auth->getIdentity();
     $year = $this->params()->fromRoute('year');
     $date = new \DateTime();
     if (!empty($year)) {
         $date->setDate($year, 1, 1);
     }
     $operationsSummaryIncome = $em->getRepository('HouseholdBudget\\Entity\\Operation')->getMonthlySummaryByType($user->getId(), 'income', $date->format('Y'));
     $operationsSummaryExpense = $em->getRepository('HouseholdBudget\\Entity\\Operation')->getMonthlySummaryByType($user->getId(), 'expense', $date->format('Y'));
     $highestIncome = 0;
     foreach ($operationsSummaryIncome as $income) {
         if ($highestIncome < $income['total']) {
             $highestIncome = $income['total'];
         }
     }
     $highestExpense = 0;
     foreach ($operationsSummaryExpense as $expense) {
         if ($highestExpense < $expense['total']) {
             $highestExpense = $expense['total'];
         }
     }
     echo '<pre>';
     //        echo var_dump($operationsSummaryIncome);
     //        echo var_dump($operationsSummaryExpense);
     echo '</pre>';
     return new ViewModel(array('operationsSummaryIncome' => $operationsSummaryIncome, 'operationsSummaryExpense' => $operationsSummaryExpense, 'highestValue' => $highestIncome > $highestExpense ? $highestIncome : $highestExpense, 'date' => $date));
 }
开发者ID:madran,项目名称:budzet_domowy,代码行数:30,代码来源:StatsController.php

示例5: execute

 /**
  *
  */
 public function execute()
 {
     $skeleton = file_get_contents($this->config->getTemplateFilename());
     $skeleton = $this->replacePlaceholder($skeleton, '%%VERSION%%', $this->version->getVersion());
     $skeleton = $this->replacePlaceholder($skeleton, '%%DATE%%', $this->now->format('Y-m-d H:i:sO'));
     $this->writeSkeletonFile($skeleton);
 }
开发者ID:paul-schulleri,项目名称:phive,代码行数:10,代码来源:SkelCommand.php

示例6: getCMSFields

 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->removeByName('ConfiguredScheduleID');
     $interval = $fields->dataFieldByName('Interval')->setDescription('Number of seconds between each run. e.g 3600 is 1 hour');
     $fields->replaceField('Interval', $interval);
     $dt = new DateTime();
     $fields->replaceField('StartDate', DateField::create('StartDate')->setConfig('dateformat', 'dd/MM/yyyy')->setConfig('showcalendar', true)->setDescription('DD/MM/YYYY e.g. ' . $dt->format('d/m/y')));
     $fields->replaceField('EndDate', DateField::create('EndDate')->setConfig('dateformat', 'dd/MM/yyyy')->setConfig('showcalendar', true)->setDescription('DD/MM/YYYY e.g. ' . $dt->format('d/m/y')));
     if ($this->ID == null) {
         foreach ($fields->dataFields() as $field) {
             //delete all included fields
             $fields->removeByName($field->Name);
         }
         $rangeTypes = ClassInfo::subclassesFor('ScheduleRange');
         $fields->addFieldToTab('Root.Main', TextField::create('Title', 'Title'));
         $fields->addFieldToTab('Root.Main', DropdownField::create('ClassName', 'Range Type', $rangeTypes));
     } else {
         $fields->addFieldToTab('Root.Main', ReadonlyField::create('ClassName', 'Type'));
     }
     if ($this->ClassName == __CLASS__) {
         $fields->removeByName('ApplicableDays');
     }
     return $fields;
 }
开发者ID:helpfulrobot,项目名称:silverstripe-australia-silverstripe-schedulizer,代码行数:25,代码来源:ScheduleRange.php

示例7: datimeStdFormat

function datimeStdFormat($relation, $DateConcept, $srcAtom, $StdFormatConcept, $formatSpec)
{
    Logger::getLogger('EXECENGINE')->debug("datimeStdFormat({$relation},{$DateConcept},{$srcAtom},{$StdFormatConcept},{$formatSpec})");
    $date = new DateTime($srcAtom);
    InsPair($relation, $DateConcept, $srcAtom, $StdFormatConcept, $date->format($formatSpec));
    Logger::getLogger('EXECENGINE')->debug("Date format {$srcAtom} changed to {$date->format($formatSpec)}");
}
开发者ID:AmpersandTarski,项目名称:Ampersand,代码行数:7,代码来源:dateTime.php

示例8: makeDecision

 public function makeDecision(DBFarmRole $dbFarmRole, Scalr_Scaling_FarmRoleMetric $farmRoleMetric, $isInvert = false)
 {
     // Get data from BW sensor
     $dbFarm = $dbFarmRole->GetFarmObject();
     $tz = $dbFarm->GetSetting(Entity\FarmSetting::TIMEZONE);
     $date = new DateTime();
     if ($tz) {
         $date->setTimezone(new DateTimeZone($tz));
     }
     $currentDate = array((int) $date->format("Hi"), $date->format("D"));
     $scaling_period = $this->db->GetRow("\n            SELECT * FROM farm_role_scaling_times\n            WHERE '{$currentDate[0]}' >= start_time\n            AND '{$currentDate[0]}' <= end_time\n            AND INSTR(days_of_week, '{$currentDate[1]}') != 0\n            AND farm_roleid = '{$dbFarmRole->ID}'\n            LIMIT 1\n        ");
     if ($scaling_period) {
         $this->logger->info("TimeScalingAlgo({$dbFarmRole->FarmID}, {$dbFarmRole->ID}) Found scaling period. Total {$scaling_period['instances_count']} instances should be running.");
         $this->instancesNumber = $scaling_period['instances_count'];
         $this->lastValue = "(" . implode(' / ', $currentDate) . ") {$scaling_period['start_time']} - {$scaling_period['end_time']} = {$scaling_period['instances_count']}";
         if ($dbFarmRole->GetRunningInstancesCount() + $dbFarmRole->GetPendingInstancesCount() < $this->instancesNumber) {
             return Scalr_Scaling_Decision::UPSCALE;
         } elseif ($dbFarmRole->GetRunningInstancesCount() + $dbFarmRole->GetPendingInstancesCount() > $this->instancesNumber) {
             return Scalr_Scaling_Decision::DOWNSCALE;
         } else {
             return Scalr_Scaling_Decision::NOOP;
         }
     } else {
         if ($dbFarmRole->GetRunningInstancesCount() > $dbFarmRole->GetSetting(Entity\FarmRoleSetting::SCALING_MIN_INSTANCES)) {
             $this->lastValue = "No period defined. Using Min instances setting.";
             return Scalr_Scaling_Decision::DOWNSCALE;
         } else {
             return Scalr_Scaling_Decision::NOOP;
         }
     }
 }
开发者ID:mheydt,项目名称:scalr,代码行数:31,代码来源:DateTime.php

示例9: getJulianDate

 /**
  * @param string $date
  * @return string
  */
 private function getJulianDate($date = 'now')
 {
     $dateTime = new \DateTime($date);
     $year = $dateTime->format('y');
     $day = str_pad($dateTime->format('z'), 3, 0, STR_PAD_LEFT);
     return $year . $day;
 }
开发者ID:Raulnet,项目名称:intranet,代码行数:11,代码来源:LicencesClubsService.php

示例10: createAdminReservation

function createAdminReservation($adminid, $userid, $equipid, $startdate, $length, $usercomment, $admincomment, $modstatus)
{
    $adminid = makeStringSafe($adminid);
    $userid = makeStringSafe($userid);
    $equipid = makeStringSafe($equipid);
    $startdate = makeStringSafe($startdate);
    $length = makeStringSafe($length);
    $usercomment = makeStringSafe($usercomment);
    $admincomment = makeStringSafe($admincomment);
    $modstatus = makeStringSafe($modstatus);
    $start_Date = new DateTime('' . $startdate . ' 00:00:00');
    $start_Date->modify("+" . $length . " day");
    //$interval = new DateInterval("P".$length."D");
    //$start_Date->add($interval);
    $enddate = $start_Date->format("Y-m-d");
    $tempdate = new DateTime('' . $enddate . ' 00:00:00');
    while ($tempdate->format("D") == "Sat" || $tempdate->format("D") == "Sun") {
        //$tempdate->add(new DateInterval("P1D"));
        $tempdate->modify("+1 day");
        $length = $length + 1;
    }
    $enddate = $tempdate->format("Y-m-d");
    doQuery("INSERT INTO " . getDBPrefix() . "_reservations SET user_id = '" . $userid . "', equip_id = '" . $equipid . "', start_date = '" . $startdate . "', end_date = '" . $enddate . "', length = '" . $length . "', pickup_time = '', user_comment = '" . $usercomment . "', admin_comment = '" . $admincomment . "', mod_status = '" . $modstatus . "'");
    $res = mysql_fetch_assoc(doQuery("SELECT res_id FROM " . getDBPrefix() . "_reservations ORDER BY res_id DESC LIMIT 1"));
    logAdminCreateReservation($adminid, $userid, $res['res_id']);
}
开发者ID:ramielrowe,项目名称:Reservation-System-V1,代码行数:26,代码来源:db_res_functions.php

示例11: getCurrent

 public function getCurrent(\DateTime $now)
 {
     $date = new \DateTime();
     $date->setTimestamp(strtotime(sprintf('%s %s of %s %d', $this->getOrdinal(), $this->getDay(), $now->format('F'), $now->format('Y'))));
     $date->setTime($now->format('H'), $now->format('i'));
     return $date;
 }
开发者ID:HackspaceJena,项目名称:RelativeDateParser,代码行数:7,代码来源:RelativeDateType1.php

示例12: isValid

 /**
  * Validate a date.
  *
  * <code>
  * $date = "01-01-2020";
  *
  * $validator = new Prism\Validator\Date($date);
  *
  * if (!$validator->isValid()) {
  * ...
  * }
  *
  * </code>
  *
  * @return bool
  */
 public function isValid()
 {
     // Check for default SQL values.
     $defaultDates = array('0000-00-00', '1000-01-01');
     if (in_array($this->date, $defaultDates, true)) {
         return false;
     }
     $string = trim($this->date);
     if ($string === '') {
         return false;
     }
     if (is_numeric($string)) {
         $string = (int) $string;
         if ($string === 0) {
             return false;
         }
         $string = '@' . $string;
     }
     try {
         $date = new \DateTime($string);
     } catch (\Exception $e) {
         return false;
     }
     $month = $date->format('m');
     $day = $date->format('d');
     $year = $date->format('Y');
     if (checkdate($month, $day, $year)) {
         return true;
     } else {
         return false;
     }
 }
开发者ID:ITPrism,项目名称:CrowdfundingDistribution,代码行数:48,代码来源:Date.php

示例13: 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->format('U'));
     $this->assertEquals($zendDate->toString(self::TIME_FORMAT_SHORT_ISO), $this->_helper->formatTime($zendDate, 'short'));
 }
开发者ID:NatashaOlut,项目名称:Mage_Test,代码行数:7,代码来源:Data.php

示例14: getGraphData

function getGraphData($users_UserID, $type, $start_date, $end_date)
{
    // Global variables provided by config.php for DB connection.
    global $con, $host, $user, $password, $db;
    if (mysqli_connect_errno()) {
        die('Could not connect: ' . mysqli_connect_error());
    }
    //Initialize index variable.
    $index = 0;
    $start_date = new DateTime($start_date);
    $end_date = new DateTime($end_date);
    while ($start_date <= $end_date) {
        $query = "SELECT * FROM sensors WHERE users_UserID = '" . $users_UserID . "' AND Type = '" . $type . "' AND Date >= '" . $start_date->format("Y-m-d") . ' 00:00:00' . "' AND Date <= '" . $start_date->format("Y-m-d") . ' 23:59:59' . "'";
        if ($result = mysqli_query($con, $query)) {
            $rowcount = mysqli_num_rows($result);
            if ($rowcount == 0) {
                // No Data for this date -- So fill with 0.
                $graphdata[$index] = 0;
            } else {
                while ($rows = mysqli_fetch_array($result)) {
                    // Insert Data into array.
                    $graphdata[$index] = $rows['Data'];
                }
            }
            mysqli_free_result($result);
        } else {
            die('Error:' . mysqli_error($con));
        }
        //Increment Start Date
        $start_date->modify('+1 day');
        //Increment index variable.
        $index++;
    }
    return $graphdata;
}
开发者ID:puzzledplane,项目名称:SE2-Cloud,代码行数:35,代码来源:getGraphData.php

示例15: __construct

 public function __construct()
 {
     $this->cachedAttributes = array();
     $date = new DateTime();
     $this->cachedAttributes["mno_session"] = "7ds8f9789a7fd7x0b898bvb8vc9h0gg";
     $this->cachedAttributes["mno_session_recheck"] = $date->format(DateTime::ISO8601);
     $this->cachedAttributes["group_uid"] = "cld-1";
     $this->cachedAttributes["group_name"] = "SomeGroupName";
     $this->cachedAttributes["group_email"] = "email@example.com";
     $this->cachedAttributes["group_role"] = "Admin";
     $this->cachedAttributes["group_end_free_trial"] = $date->format(DateTime::ISO8601);
     $this->cachedAttributes["group_has_credit_card"] = "true";
     $this->cachedAttributes["group_currency"] = "USD";
     $this->cachedAttributes["group_timezone"] = "America/Los_Angeles";
     $this->cachedAttributes["group_country"] = "US";
     $this->cachedAttributes["group_city"] = "Los Angeles";
     $this->cachedAttributes["uid"] = "usr-1";
     $this->cachedAttributes["virtual_uid"] = "user-1.cld-1";
     $this->cachedAttributes["email"] = "j.doe@doecorp.com";
     $this->cachedAttributes["virtual_email"] = "user-1.cld-1@mail.maestrano.com";
     $this->cachedAttributes["name"] = "John";
     $this->cachedAttributes["surname"] = "Doe";
     $this->cachedAttributes["country"] = "AU";
     $this->cachedAttributes["company_name"] = "DoeCorp";
 }
开发者ID:maestrano,项目名称:maestrano-php,代码行数:25,代码来源:SamlMnoRespStub.php


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