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


PHP Time::parseDateTime方法代码示例

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


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

示例1: render

    /**
     * Renders a date time widget.
     *
     * @param array $data Data to render with.
     * @param \Cake\View\Form\ContextInterface $context The current form context.
     * @return string A generated select box.
     * @throws \RuntimeException When option data is invalid.
     */
    public function render(array $data, ContextInterface $context)
    {
        $id = $data['id'];
        $name = $data['name'];
        $val = $data['val'];
        $type = $data['type'];
        $required = $data['required'] ? 'required' : '';
        $disabled = isset($data['disabled']) && $data['disabled'] ? 'disabled' : '';
        $role = isset($data['role']) ? $data['role'] : 'datetime-picker';
        $format = null;
        $locale = isset($data['locale']) ? $data['locale'] : I18n::locale();
        $timezoneAware = Configure::read('CrudView.timezoneAwareDateTimeWidget');
        $timestamp = null;
        $timezoneOffset = null;
        if (isset($data['data-format'])) {
            $format = $this->_convertPHPToMomentFormat($data['data-format']);
        }
        if (!$val instanceof DateTimeInterface && !empty($val)) {
            $val = $type === 'date' ? Time::parseDate($val) : Time::parseDateTime($val);
        }
        if ($val) {
            if ($timezoneAware) {
                $timestamp = $val->format('U');
                $dateTimeZone = new DateTimeZone(date_default_timezone_get());
                $timezoneOffset = $dateTimeZone->getOffset($val) / 60;
            }
            $val = $val->format($type === 'date' ? 'Y-m-d' : 'Y-m-d H:i:s');
        }
        if (!$format) {
            $format = $type === 'date' ? 'L' : 'L LT';
        }
        $widget = <<<html
            <div class="input-group {$type}">
                <input
                    type="text"
                    class="form-control"
                    name="{$name}"
                    value="{$val}"
                    id="{$id}"
                    role="{$role}"
                    data-locale="{$locale}"
                    data-format="{$format}"
html;
        if ($timezoneAware && isset($timestamp, $timezoneOffset)) {
            $widget .= <<<html
                    data-timestamp="{$timestamp}"
                    data-timezone-offset="{$timezoneOffset}"
html;
        }
        $widget .= <<<html
                    {$required}
                    {$disabled}
                />
                <label for="{$id}" class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </label>
            </div>
html;
        return $widget;
    }
开发者ID:friendsofcake,项目名称:crud-view,代码行数:68,代码来源:DateTimeWidget.php

示例2: render

    /**
     * Renders a date time widget.
     *
     * @param array $data Data to render with.
     * @param \Cake\View\Form\ContextInterface $context The current form context.
     * @return string A generated select box.
     * @throws \RuntimeException When option data is invalid.
     */
    public function render(array $data, ContextInterface $context)
    {
        $id = $data['id'];
        $name = $data['name'];
        $val = $data['val'];
        $type = $data['type'];
        $required = $data['required'] ? 'required' : '';
        $role = isset($data['role']) ? $data['role'] : 'datetime-picker';
        $format = null;
        $timestamp = null;
        $locale = locale_get_primary_language(I18n::locale());
        if (isset($data['data-format'])) {
            $format = $this->_convertPHPToMomentFormat($data['data-format']);
        }
        if (!$val instanceof DateTime && !empty($val)) {
            $val = $type === 'date' ? Time::parseDate($val) : Time::parseDateTime($val);
        }
        if ($val) {
            $timestamp = $val->format('U');
            $val = $val->format($type === 'date' ? 'Y-m-d' : 'Y-m-d H:i:s');
        }
        if (!$format) {
            $format = $type === 'date' ? 'L' : 'L LT';
        }
        $widget = <<<html
            <div class="input-group {$type}">
                <input
                    type="text"
                    class="form-control"
                    name="{$name}"
                    value="{$val}"
                    id="{$id}"
                    role="{$role}"
                    data-locale="{$locale}"
                    data-format="{$format}"
                    data-timestamp="{$timestamp}"
                    {$required}
                />
                <span class="input-group-addon">
                    <span class="glyphicon glyphicon-calendar"></span>
                </span>
            </div>
html;
        return $widget;
    }
开发者ID:Wouter0100,项目名称:crud-view,代码行数:53,代码来源:DateTimeWidget.php

示例3: initialize

 /**
  * Initialize method
  *
  * @param array $config The configuration for the Table.
  * @return void
  */
 public function initialize(array $config)
 {
     parent::initialize($config);
     $this->table('lumisials');
     $this->displayField('name');
     $this->primaryKey('id');
     $this->hasMany('Accounts', ['foreignKey' => 'lumisial_id']);
     $this->hasMany('Bills', ['foreignKey' => 'lumisial_id']);
     $this->hasMany('Boards', ['foreignKey' => 'lumisial_id']);
     $this->hasMany('Furnitures', ['foreignKey' => 'lumisial_id']);
     $this->hasMany('Materials', ['foreignKey' => 'lumisial_id']);
     $this->hasMany('Members', ['foreignKey' => 'lumisial_id']);
     $this->eventManager()->on('Model.beforeMarshal', function ($event, $data) {
         if (!empty($data['consag_date']) && is_string($data['consag_date'])) {
             $data['consag_date'] = Time::parseDateTime($data['consag_date'], 'dd/MM/yyyy');
         }
     });
 }
开发者ID:joaorsb,项目名称:lumisial,代码行数:24,代码来源:LumisialsTable.php

示例4: initialize

 /**
  * Initialize method
  *
  * @param array $config The configuration for the Table.
  * @return void
  */
 public function initialize(array $config)
 {
     parent::initialize($config);
     $this->table('bills');
     $this->displayField('name');
     $this->primaryKey('id');
     $this->belongsTo('Lumisials', ['foreignKey' => 'lumisial_id', 'joinType' => 'INNER']);
     $this->belongsTo('Accounts', ['foreignKey' => 'account_id', 'joinType' => 'INNER']);
     $this->hasMany('Statements', ['foreignKey' => 'bill_id', 'joinType' => 'INNER']);
     $this->eventManager()->on('Model.beforeMarshal', function ($event, $data) {
         if (!empty($data['expire_date']) && is_string($data['expire_date'])) {
             $data['expire_date'] = Time::parseDateTime($data['expire_date'], 'dd/MM/yyyy');
         }
         if (!empty($data['payment_date']) && is_string($data['payment_date'])) {
             $data['payment_date'] = Time::parseDateTime($data['payment_date'], 'dd/MM/yyyy');
         }
     });
 }
开发者ID:joaorsb,项目名称:lumisial,代码行数:24,代码来源:BillsTable.php

示例5: initialize

 /**
  * Initialize method
  *
  * @param array $config The configuration for the Table.
  * @return void
  */
 public function initialize(array $config)
 {
     parent::initialize($config);
     $this->table('members');
     $this->displayField('name');
     $this->primaryKey('id');
     $this->addBehavior('Timestamp');
     $this->belongsTo('Lumisials', ['foreignKey' => 'lumisial_id', 'joinType' => 'INNER']);
     $this->hasMany('Donations', ['foreignKey' => 'member_id']);
     $this->hasMany('Furnitures', ['foreignKey' => 'member_id']);
     $this->hasMany('Materials', ['foreignKey' => 'member_id']);
     $this->belongsToMany('Boards', ['foreignKey' => 'member_id', 'targetForeignKey' => 'board_id', 'joinTable' => 'boards_members']);
     $this->eventManager()->on('Model.beforeMarshal', function ($event, $data) {
         if (!empty($data['consag_date']) && is_string($data['consag_date'])) {
             $data['consag_date'] = Time::parseDateTime($data['consag_date'], 'dd/MM/yyyy');
         }
     });
 }
开发者ID:joaorsb,项目名称:lumisial,代码行数:24,代码来源:MembersTable.php

示例6: testParseDateTime

 /**
  * Tests parsing a string into a Time object based on the locale format.
  *
  * @return void
  */
 public function testParseDateTime()
 {
     $time = Time::parseDateTime('10/13/2013 12:54am');
     $this->assertNotNull($time);
     $this->assertEquals('2013-10-13 00:54', $time->format('Y-m-d H:i'));
     Time::$defaultLocale = 'fr-FR';
     $time = Time::parseDateTime('13 10, 2013 12:54');
     $this->assertNotNull($time);
     $this->assertEquals('2013-10-13 12:54', $time->format('Y-m-d H:i'));
     $time = Time::parseDateTime('13 foo 10 2013 12:54');
     $this->assertNull($time);
 }
开发者ID:RogerSchmeier,项目名称:Webtruck,代码行数:17,代码来源:TimeTest.php


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