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


PHP DateTime::createFromFormat方法代码示例

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


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

示例1: __construct

 /**
  * Class constructor.
  */
 public function __construct(ProjectService $projectService)
 {
     parent::__construct();
     $this->setAttribute('method', 'post');
     $this->setAttribute('class', 'form-horizontal');
     $this->setAttribute('id', 'create-report');
     /*
      * Create an array with possible periods. This will trigger a date but display a period (semester)
      */
     $semesterOptions = [];
     foreach ($projectService->parseYearRange() as $year) {
         /*
          * Use the Report object to parse the data
          */
         $report = new Report();
         $report->setDatePeriod(\DateTime::createFromFormat('Y-m-d', $year . '-03-01'));
         $semesterOptions[$year . '-1'] = $report->parseName();
         $report->setDatePeriod(\DateTime::createFromFormat('Y-m-d', $year . '-09-01'));
         $semesterOptions[$year . '-2'] = $report->parseName();
     }
     $this->add(['type' => 'Zend\\Form\\Element\\Select', 'name' => 'period', 'options' => ['label' => _("txt-report-period"), 'help-block' => _("txt-report-period-explanation"), 'value_options' => $semesterOptions], 'attributes' => ['class' => "form-control", 'id' => "period"]]);
     $this->add(['type' => 'Zend\\Form\\Element\\Text', 'name' => 'item', 'options' => ['label' => _("txt-document-name"), 'help-block' => _("txt-document-name-explanation")], 'attributes' => ['placeholder' => _("txt-please-give-a-document-name")]]);
     $this->add(['type' => '\\Zend\\Form\\Element\\File', 'name' => 'file', 'options' => ["label" => "txt-file", "help-block" => _("txt-file-requirements")]]);
     $this->add(['type' => 'Zend\\Form\\Element\\Submit', 'name' => 'submit', 'attributes' => ['class' => "btn btn-primary", 'value' => _("txt-create")]]);
     $this->add(['type' => 'Zend\\Form\\Element\\Submit', 'name' => 'cancel', 'attributes' => ['class' => "btn btn-warning", 'value' => _("txt-cancel")]]);
 }
开发者ID:debranova,项目名称:project,代码行数:29,代码来源:CreateReport.php

示例2: create

 /**
  * Creates token
  * @param string $type Type of the token
  * @param string $name Name of the token unique for selected type
  * @param callable|AlgorithmInterface $algorithm Algorithm of the token generation
  * @param int|\DateTime|Expression $expire Expiration date of the token
  * @return static
  */
 public static function create($type, $name, $algorithm = null, $expire = null)
 {
     if ($algorithm === null) {
         $algorithm = new RandomString();
     }
     $token = static::findOne(['type' => $type, 'name' => $name]);
     if ($token == null) {
         $token = new static();
     }
     $token->type = $type;
     $token->name = $name;
     if (is_callable($algorithm)) {
         $token->token = call_user_func($algorithm);
     } else {
         $token->token = $algorithm->generate();
     }
     if (is_integer($expire)) {
         $token->expire_at = \DateTime::createFromFormat('U', $expire, new \DateTimeZone('UTC'))->setTimezone(new \DateTimeZone('MSK'))->format('Y-m-d H:i:s');
     } elseif ($expire instanceof \DateTime) {
         $token->expire_at = $expire->format('Y-m-d h:i:s');
     } else {
         $token->expire_at = $expire;
     }
     $token->created_at = new Expression('NOW()');
     $token->save(false);
     return $token;
 }
开发者ID:omnilight,项目名称:yii2-tokens,代码行数:35,代码来源:Token.php

示例3: setAssignments

 public function setAssignments()
 {
     $request = self::$_appInstance->request();
     $post_data = json_decode($request->post('data'));
     $table = 'student_exam_assignment';
     if (!isset($post_data[0])) {
         $results['message'] = 'เกิดข้อผิดพลาดในการบันทึกข้อมูล';
         $results['error'] = true;
     }
     $date = new DateTime("now");
     $startAssignment = $date->createFromFormat('d/m/Y', $post_data[0]->startAssignment)->format('Y-m-d');
     $endAssignment = $date->createFromFormat('d/m/Y', $post_data[0]->endAssignment)->format('Y-m-d');
     $isError = true;
     foreach ($post_data as $savedata) {
         # code...
         $data['student_course_id'] = $savedata->student_course_id;
         $data['assign_by'] = $savedata->assign_by;
         $data['exam_random_history_id'] = $savedata->exam_random_history_id;
         $data['start_assignment'] = $startAssignment;
         $data['end_assignment'] = $endAssignment;
         $data['assign_date'] = $date->format('Y-m-d H:i:s');
         if (!self::isAlreadyExist($data)) {
             $id = PDOAdpter::getInstance()->insert($data, $table);
             $isError = !isset($id);
             $results['message'] = $isError ? 'เกิดข้อผิดพลาดในการบันทึกข้อมูล' : 'บันทึกข้อมูลเสร็จเรียบร้อย';
         } else {
             $results['message'] = "พบข้อมูลซ้ำในระบบฐานข้อมูล";
         }
     }
     $results['route'] = 'list_of_exams.php';
     $results['isError'] = $isError;
     echo json_encode($results);
 }
开发者ID:edupol,项目名称:examsystem,代码行数:33,代码来源:ExamAssignment.php

示例4: getLastMonths

 /**
  * @param int $numberOfMonths
  * @return array|bool
  */
 public function getLastMonths($numberOfMonths = 12)
 {
     $statistics = [];
     $date = new \DateTime();
     $startDate = time() - $numberOfMonths * 60 * 60 * 24 * 30;
     $this->setTableName('comments');
     $rows = $this->fetchAll('time >= "' . date('Y-m-01 H:i:s', $startDate) . '"')->toArray();
     foreach ($rows as $row) {
         $row['time'] = $date->createFromFormat('Y-m-d H:i:s', $row['time'])->format('Y') . ' Q' . floor(date("m", $date->createFromFormat('Y-m-d H:i:s', $row['time'])->getTimestamp()) / 3);
         $statistics[$row['time']]['comments']++;
     }
     $this->setTableName('posts');
     $rows = $this->fetchAll('time >= "' . date('Y-m-01 H:i:s', $startDate) . '"')->toArray();
     foreach ($rows as $row) {
         $row['time'] = $date->createFromFormat('Y-m-d H:i:s', $row['time'])->format('Y') . ' Q' . floor(date("m", $date->createFromFormat('Y-m-d H:i:s', $row['time'])->getTimestamp()) / 3);
         $statistics[$row['time']]['posts']++;
     }
     $this->setTableName('notifications');
     $rows = $this->fetchAll('time >= "' . date('Y-m-01 H:i:s', $startDate) . '"')->toArray();
     foreach ($rows as $row) {
         $row['time'] = $date->createFromFormat('Y-m-d H:i:s', $row['time'])->format('Y') . ' Q' . floor(date("m", $date->createFromFormat('Y-m-d H:i:s', $row['time'])->getTimestamp()) / 3);
         $statistics[$row['time']]['notifications']++;
     }
     $this->setTableName('users');
     $rows = $this->fetchAll('registered >= "' . date('Y-m-01 H:i:s', $startDate) . '"')->toArray();
     foreach ($rows as $row) {
         $row['time'] = $row['registered'];
         $row['time'] = $date->createFromFormat('Y-m-d H:i:s', $row['time'])->format('Y') . ' Q' . floor(date("m", $date->createFromFormat('Y-m-d H:i:s', $row['time'])->getTimestamp()) / 3);
         $statistics[$row['time']]['users']++;
     }
     return $statistics;
 }
开发者ID:rcrrich,项目名称:cunity,代码行数:36,代码来源:Statistics.php

示例5: handleTypeConversions

 protected function handleTypeConversions($value, $typeOfField)
 {
     if ($typeOfField == 'datetime') {
         return \DateTime::createFromFormat('d/m/Y', $value);
     }
     return parent::handleTypeConversions($value, $typeOfField);
 }
开发者ID:Primetron,项目名称:Edusoft,代码行数:7,代码来源:DateHydrator.php

示例6: __construct

 /**
  * @param String The line to parse
  */
 public function __construct($string)
 {
     parent::__construct($string);
     $result = new COSResult();
     $result->setFileIdentifier(trim($this->columns[self::OFFSET_FILE_ID]));
     $result->setPaymentId(trim($this->columns[self::OFFSET_PAYMENT_ID]));
     $result->setTransactionId(trim($this->columns[self::OFFSET_TRANSACTION_ID]));
     $result->setInstrumentType(trim($this->columns[self::OFFSET_INSTRUMENT_TYPE]));
     $result->setInstrumentNumber(trim($this->columns[self::OFFSET_INSTRUMENT_NUMBER]));
     //datetime is now patched to return d/m/Y
     $datetime = \DateTime::createFromFormat('d/m/y', trim($this->columns[self::OFFSET_INSTRUMENT_DATE]));
     if (!$datetime) {
         $datetime = \DateTime::createFromFormat('d/m/Y', trim($this->columns[self::OFFSET_INSTRUMENT_DATE]));
     }
     $result->setDateTime($datetime);
     $result->setCurrency(trim($this->columns[self::OFFSET_CURRENCY]));
     $result->setAmount(trim($this->columns[self::OFFSET_AMOUNT]));
     //debit_date is now patched to return d/m/Y
     $debit_date = \DateTime::createFromFormat('d/m/y', trim($this->columns[self::OFFSET_DEBIT_DATE]));
     if (!$debit_date) {
         $debit_date = \DateTime::createFromFormat('d/m/Y', trim($this->columns[self::OFFSET_DEBIT_DATE]));
     }
     $result->setDebitDate($debit_date);
     $result->setStatus(trim($this->columns[self::OFFSET_STATUS]));
     //status_date is now patched to return d/m/Y
     $status_date = \DateTime::createFromFormat('d/m/y', trim($this->columns[self::OFFSET_STATUS_DATE]));
     if (!$status_date) {
         $status_date = \DateTime::createFromFormat('d/m/Y', trim($this->columns[self::OFFSET_STATUS_DATE]));
     }
     $result->setStatusDate($status_date);
     $result->setBeneficiaryId(trim($this->columns[self::OFFSET_BENEFICIARY_ID]));
     $result->setFullname(trim($this->columns[self::OFFSET_BENEFICIARY_NAME]));
     $this->cosResult = $result;
 }
开发者ID:chalcedonyt,项目名称:laravel-cos-processor,代码行数:37,代码来源:HSBCCOSResultAdapter.php

示例7: buildData

 protected function buildData($line, $line_number = null)
 {
     $row = parent::buildData($line, $line_number);
     if (isset($row[$this->structConfig['config']['date_field']])) {
         if ($row['type'] == 'mmsc') {
             $datetime = DateTime::createFromFormat($this->structConfig['config']['date_format'], preg_replace('/^(\\d+)\\+(\\d)$/', '$1+0$2:00', $row[$this->structConfig['config']['date_field']]));
             $matches = array();
             if (preg_match("/^\\+*(\\d+)\\//", $row['recipent_addr'], $matches)) {
                 $row['called_number'] = $matches[1];
             }
         } else {
             if (isset($row[$this->structConfig['config']['date_field']])) {
                 $offset = (isset($this->structConfig['config']['date_offset']) && isset($row[$this->structConfig['config']['date_offset']]) ? ($row[$this->structConfig['config']['date_offset']] > 0 ? "+" : "") . $row[$this->structConfig['config']['date_offset']] : "00") . ':00';
                 $datetime = DateTime::createFromFormat($this->structConfig['config']['date_format'], $row[$this->structConfig['config']['date_field']] . $offset);
             }
         }
         if (isset($row[$this->structConfig['config']['calling_number_field']])) {
             $row[$this->structConfig['config']['calling_number_field']] = Billrun_Util::msisdn($row[$this->structConfig['config']['calling_number_field']]);
         }
         if (isset($row[$this->structConfig['config']['called_number_field']])) {
             $row[$this->structConfig['config']['called_number_field']] = Billrun_Util::msisdn($row[$this->structConfig['config']['called_number_field']]);
         }
         $row['urt'] = new MongoDate($datetime->format('U'));
     }
     return $row;
 }
开发者ID:ngchie,项目名称:system,代码行数:26,代码来源:Sms.php

示例8: getCacheObject

 /**
  * @param RequestInterface $request
  * @param ResponseInterface $response
  * @return CacheEntry|null entry to save, null if can't cache it
  */
 protected function getCacheObject(RequestInterface $request, ResponseInterface $response)
 {
     if (!isset($this->statusAccepted[$response->getStatusCode()])) {
         // Don't cache it
         return;
     }
     $cacheControl = new KeyValueHttpHeader($response->getHeader('Cache-Control'));
     $varyHeader = new KeyValueHttpHeader($response->getHeader('Vary'));
     if ($varyHeader->has('*')) {
         // This will never match with a request
         return;
     }
     if ($cacheControl->has('no-store')) {
         // No store allowed (maybe some sensitives data...)
         return;
     }
     if ($cacheControl->has('no-cache')) {
         // Stale response see RFC7234 section 5.2.1.4
         $entry = new CacheEntry($request, $response, new \DateTime('-1 seconds'));
         return $entry->hasValidationInformation() ? $entry : null;
     }
     foreach ($this->ageKey as $key) {
         if ($cacheControl->has($key)) {
             return new CacheEntry($request, $response, new \DateTime('+' . (int) $cacheControl->get($key) . 'seconds'));
         }
     }
     if ($response->hasHeader('Expires')) {
         $expireAt = \DateTime::createFromFormat(\DateTime::RFC1123, $response->getHeaderLine('Expires'));
         if ($expireAt !== false) {
             return new CacheEntry($request, $response, $expireAt);
         }
     }
     return new CacheEntry($request, $response, new \DateTime('-1 seconds'));
 }
开发者ID:kevinrob,项目名称:guzzle-cache-middleware,代码行数:39,代码来源:PrivateCacheStrategy.php

示例9: printTweet

function printTweet($tweet, $boolean, $key)
{
    global $happyValueArray;
    $datetime = $tweet['created_at'];
    $new_date = DateTime::createFromFormat('D M d H:i:s O Y', $datetime);
    $new_date = $new_date->format('M d');
    if ($boolean) {
        echo '<div class="container">';
        echo '<div class="row">';
        echo '<div class="col-md-1">';
        echo "<a href={$tweet['user']['url']}><img src={$tweet['user']['profile_image_url']} height='42' width='42'></a>";
        echo '</div>';
        echo '<div class="cold-md-11">';
        echo "<a href={$tweet['user']['url']}>{$tweet['user']['screen_name']}</a> • {$new_date}<br>{$tweet['text']} || Happy = <b><i>" . $happyValueArray[$key] . "</b></i>";
        echo '</div> </div> </div> <br>';
    } else {
        echo '<div class="container">';
        echo '<div class="row">';
        echo '<div class="col-md-1">';
        echo "<a href={$tweet['user']['url']}><img src={$tweet['user']['profile_image_url']} height='42' width='42'></a>";
        echo '</div>';
        echo '<div class="cold-md-11">';
        echo "<a href={$tweet['user']['url']}>{$tweet['user']['screen_name']}</a> • {$new_date}<br>{$tweet['text']}";
        echo '</div> </div> </div> <br>';
    }
}
开发者ID:SocialSpaces,项目名称:TweedStudy,代码行数:26,代码来源:index2.2.php

示例10: get_last_update

 public function get_last_update()
 {
     global $conf;
     $update_file = file_get_contents($conf['updatefile']);
     $last_update = DateTime::createFromFormat('d.m.Y H:i:s', $update_file);
     return $last_update;
 }
开发者ID:baltruschat,项目名称:selectconnect,代码行数:7,代码来源:cartridge.php

示例11: getNearestWeekday

 private static function getNearestWeekday($currentYear, $currentMonth, $targetDay)
 {
     $vmbiuiwr = "targetDay";
     ${${"GLOBALS"}["tchumjbel"]} = str_pad(${$vmbiuiwr}, 2, "0", STR_PAD_LEFT);
     $qvlloj = "lastDayOfMonth";
     ${"GLOBALS"}["akfjkh"] = "currentWeekday";
     ${${"GLOBALS"}["eagven"]} = \DateTime::createFromFormat("Y-m-d", "{$currentYear}-{$currentMonth}-{$tday}");
     ${${"GLOBALS"}["akfjkh"]} = (int) $target->format("N");
     if (${${"GLOBALS"}["lbniwfpf"]} < 6) {
         return ${${"GLOBALS"}["eagven"]};
     }
     ${$qvlloj} = $target->format("t");
     ${"GLOBALS"}["tdhsywdt"] = "i";
     foreach (array(-1, 1, -2, 2) as ${${"GLOBALS"}["tdhsywdt"]}) {
         ${"GLOBALS"}["rkhwmmreckl"] = "adjusted";
         ${"GLOBALS"}["vlvpyeexjroc"] = "adjusted";
         ${${"GLOBALS"}["rkhwmmreckl"]} = ${${"GLOBALS"}["cliypxb"]} + ${${"GLOBALS"}["pmnsmmcihwt"]};
         if (${${"GLOBALS"}["vlvpyeexjroc"]} > 0 && ${${"GLOBALS"}["quxzvrczu"]} <= ${${"GLOBALS"}["bppewpecifg"]}) {
             ${"GLOBALS"}["neicmchryn"] = "adjusted";
             ${"GLOBALS"}["bqllkuevy"] = "currentYear";
             $target->setDate(${${"GLOBALS"}["bqllkuevy"]}, ${${"GLOBALS"}["vrhapbb"]}, ${${"GLOBALS"}["neicmchryn"]});
             if ($target->format("N") < 6 && $target->format("m") == ${${"GLOBALS"}["vrhapbb"]}) {
                 return ${${"GLOBALS"}["eagven"]};
             }
         }
     }
 }
开发者ID:cin-system,项目名称:vtigercrm-cin,代码行数:27,代码来源:DayOfMonthField.php

示例12: testOutputObject

 public function testOutputObject()
 {
     $this->_user->setId(1);
     $this->_user->setSurname('John');
     $this->_user->setLastname('Doe');
     $birthDate = \DateTime::createFromFormat('Y-m-d', '1982-07-05');
     $this->_user->setBirthdate($birthDate);
     $group = new Entity\Group();
     $group->setId(1);
     $group->setName('admin');
     $this->_user->addGroup($group);
     $expected = new \stdClass();
     $expected->id = 1;
     $expected->url = '/users/1';
     $expected->surname = 'John';
     $expected->lastname = 'Doe';
     $expected->birthdate = '1982-07-05';
     $expectedGroup = new \stdClass();
     $expectedGroup->id = 1;
     $expectedGroup->url = "/groups/1";
     $expectedGroup->name = "admin";
     $expectedGroup->created = $group->getCreated()->format(\Pollex\Entity\Base::DATE_FORMAT);
     $expectedGroup->updated = $group->getUpdated()->format(\Pollex\Entity\Base::DATE_FORMAT);
     $expected->groups = array($expectedGroup);
     $expected->created = $this->_user->getCreated()->format(Entity\Base::DATE_FORMAT);
     $expected->updated = $this->_user->getUpdated()->format(Entity\Base::DATE_FORMAT);
     $this->assertEquals($expected, $this->_user->getOutputObject());
 }
开发者ID:newloki,项目名称:pollex,代码行数:28,代码来源:UserTest.php

示例13: generate

 /**
  * Generate the special date
  */
 protected function generate()
 {
     $this->description = 'Oudjaarsdag';
     $this->startDate = \DateTime::createFromFormat('Y-m-d', $this->year . '-12-31');
     $this->endDate = \DateTime::createFromFormat('Y-m-d', $this->year . '-12-31');
     $this->totalLength = 1;
 }
开发者ID:stefanius,项目名称:special-dates,代码行数:10,代码来源:LastDayOfYear.php

示例14: getBirthDate

 /**
  * Returns the driver birth date.
  *
  * @return \DateTime|null
  */
 public function getBirthDate()
 {
     if (empty($this->birthDate)) {
         return null;
     }
     return \DateTime::createFromFormat('Y-m-d|', $this->birthDate);
 }
开发者ID:brieucthomas,项目名称:ergast-client,代码行数:12,代码来源:Driver.php

示例15: testLatins

 public function testLatins()
 {
     $objSign = new ZodiacSign(\DateTime::createFromFormat('Y-m-d', '2000-03-21'));
     $this->assertEquals('aries', $objSign->getLatin());
     $objSign = new ZodiacSign(\DateTime::createFromFormat('Y-m-d', '2000-04-20'));
     $this->assertEquals('taurus', $objSign->getLatin());
     $objSign = new ZodiacSign(\DateTime::createFromFormat('Y-m-d', '2000-05-21'));
     $this->assertEquals('gemini', $objSign->getLatin());
     $objSign = new ZodiacSign(\DateTime::createFromFormat('Y-m-d', '2000-06-21'));
     $this->assertEquals('cancer', $objSign->getLatin());
     $objSign = new ZodiacSign(\DateTime::createFromFormat('Y-m-d', '2000-07-23'));
     $this->assertEquals('leo', $objSign->getLatin());
     $objSign = new ZodiacSign(\DateTime::createFromFormat('Y-m-d', '2000-08-23'));
     $this->assertEquals('virgo', $objSign->getLatin());
     $objSign = new ZodiacSign(\DateTime::createFromFormat('Y-m-d', '2000-09-23'));
     $this->assertEquals('libra', $objSign->getLatin());
     $objSign = new ZodiacSign(\DateTime::createFromFormat('Y-m-d', '2000-10-23'));
     $this->assertEquals('scorpio', $objSign->getLatin());
     $objSign = new ZodiacSign(\DateTime::createFromFormat('Y-m-d', '2000-11-22'));
     $this->assertEquals('sagittarius', $objSign->getLatin());
     $objSign = new ZodiacSign(\DateTime::createFromFormat('Y-m-d', '2000-12-22'));
     $this->assertEquals('capricorn', $objSign->getLatin());
     $objSign = new ZodiacSign(\DateTime::createFromFormat('Y-m-d', '2000-01-20'));
     $this->assertEquals('aquarius', $objSign->getLatin());
     $objSign = new ZodiacSign(\DateTime::createFromFormat('Y-m-d', '2000-02-19'));
     $this->assertEquals('pisces', $objSign->getLatin());
 }
开发者ID:codefog,项目名称:contao-haste,代码行数:27,代码来源:ZodiacSignTest.php


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