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


PHP Date::create方法代码示例

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


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

示例1: Form

 public function Form()
 {
     $fields = new FieldList();
     $source = array();
     $fields->push(new HeaderField('Header', _t('RemoveOrphanedPagesTask.HEADER', 'Remove all orphaned pages task')));
     $fields->push(new LiteralField('Description', $this->description));
     $orphans = $this->getOrphanedPages($this->orphanedSearchClass);
     if ($orphans) {
         foreach ($orphans as $orphan) {
             $latestVersion = Versioned::get_latest_version($this->orphanedSearchClass, $orphan->ID);
             $latestAuthor = DataObject::get_by_id('Member', $latestVersion->AuthorID);
             $stageRecord = Versioned::get_one_by_stage($this->orphanedSearchClass, 'Stage', sprintf("\"%s\".\"ID\" = %d", ClassInfo::baseDataClass($this->orphanedSearchClass), $orphan->ID));
             $liveRecord = Versioned::get_one_by_stage($this->orphanedSearchClass, 'Live', sprintf("\"%s\".\"ID\" = %d", ClassInfo::baseDataClass($this->orphanedSearchClass), $orphan->ID));
             $label = sprintf('<a href="admin/pages/edit/show/%d">%s</a> <small>(#%d, Last Modified Date: %s, Last Modifier: %s, %s)</small>', $orphan->ID, $orphan->Title, $orphan->ID, Date::create($orphan->LastEdited)->Nice(), $latestAuthor ? $latestAuthor->Title : 'unknown', $liveRecord ? 'is published' : 'not published');
             $source[$orphan->ID] = $label;
         }
     }
     if ($orphans && $orphans->Count()) {
         $fields->push(new CheckboxSetField('OrphanIDs', false, $source));
         $fields->push(new LiteralField('SelectAllLiteral', sprintf('<p><a href="#" onclick="javascript:jQuery(\'#Form_Form_OrphanIDs :checkbox\').attr(\'checked\', \'checked\'); return false;">%s</a>&nbsp;', _t('RemoveOrphanedPagesTask.SELECTALL', 'select all'))));
         $fields->push(new LiteralField('UnselectAllLiteral', sprintf('<a href="#" onclick="javascript:jQuery(\'#Form_Form_OrphanIDs :checkbox\').attr(\'checked\', \'\'); return false;">%s</a></p>', _t('RemoveOrphanedPagesTask.UNSELECTALL', 'unselect all'))));
         $fields->push(new OptionSetField('OrphanOperation', _t('RemoveOrphanedPagesTask.CHOOSEOPERATION', 'Choose operation:'), array('rebase' => _t('RemoveOrphanedPagesTask.OPERATION_REBASE', sprintf('Rebase selected to a new holder page "%s" and unpublish. None of these pages will show up for website visitors.', $this->rebaseHolderTitle())), 'remove' => _t('RemoveOrphanedPagesTask.OPERATION_REMOVE', 'Remove selected from all stages (WARNING: Will destroy all selected pages from both stage and live)')), 'rebase'));
         $fields->push(new LiteralField('Warning', sprintf('<p class="message">%s</p>', _t('RemoveOrphanedPagesTask.DELETEWARNING', 'Warning: These operations are not reversible. Please handle with care.'))));
     } else {
         $fields->push(new LiteralField('NotFoundLabel', sprintf('<p class="message">%s</p>', _t('RemoveOrphanedPagesTask.NONEFOUND', 'No orphans found'))));
     }
     $form = new Form($this, 'Form', $fields, new FieldList(new FormAction('doSubmit', _t('RemoveOrphanedPagesTask.BUTTONRUN', 'Run'))));
     if (!$orphans || !$orphans->Count()) {
         $form->makeReadonly();
     }
     return $form;
 }
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:32,代码来源:RemoveOrphanedPagesTask.php

示例2: fromDOMtoDB

 function fromDOMtoDB($domValue)
 {
     if (empty($domValue)) {
         $domValue = Date::create(0);
     }
     return $domValue->format("%Y-%m-%d %H:%M:%S");
 }
开发者ID:aeberh,项目名称:php-movico,代码行数:7,代码来源:DateConverter.php

示例3: __construct

 public function __construct(Date $base, $weekStart = Timestamp::WEEKDAY_MONDAY)
 {
     $firstDayOfMonth = Date::create($base->getYear() . '-' . $base->getMonth() . '-01');
     $lastDayOfMonth = Date::create($base->getYear() . '-' . $base->getMonth() . '-' . date('t', $base->toStamp()));
     $start = $firstDayOfMonth->getFirstDayOfWeek($weekStart);
     $end = $lastDayOfMonth->getLastDayOfWeek($weekStart);
     $this->monthRange = DateRange::create()->lazySet($firstDayOfMonth, $lastDayOfMonth);
     $this->fullRange = DateRange::create()->lazySet($start, $end);
     $rawDays = $this->fullRange->split();
     $this->fullLength = 0;
     foreach ($rawDays as $rawDay) {
         $day = CalendarDay::create($rawDay->toStamp());
         if ($this->monthRange->contains($day)) {
             $day->setOutside(false);
         } else {
             $day->setOutside(true);
         }
         $this->days[$day->toDate()] = $day;
         $weekNumber = floor($this->fullLength / 7);
         if (!isset($this->weeks[$weekNumber])) {
             $this->weeks[$weekNumber] = CalendarWeek::create();
         }
         $this->weeks[$weekNumber]->addDay($day);
         ++$this->fullLength;
     }
     ++$this->fullLength;
 }
开发者ID:onphp-framework,项目名称:onphp-framework,代码行数:27,代码来源:CalendarMonthWeekly.class.php

示例4: getArchive

 /**
  * Returns a list of months where blog posts are present.
  *
  * @return DataList
  */
 public function getArchive()
 {
     $query = $this->Blog()->getBlogPosts()->dataQuery();
     if ($this->ArchiveType == 'Yearly') {
         $query->groupBy('DATE_FORMAT("PublishDate", \'%Y\')');
     } else {
         $query->groupBy('DATE_FORMAT("PublishDate", \'%Y-%M\')');
     }
     $posts = $this->Blog()->getBlogPosts()->setDataQuery($query);
     if ($this->NumberToDisplay > 0) {
         $posts = $posts->limit($this->NumberToDisplay);
     }
     $archive = new ArrayList();
     if ($posts->count() > 0) {
         foreach ($posts as $post) {
             /**
              * @var BlogPost $post
              */
             $date = Date::create();
             $date->setValue($post->PublishDate);
             if ($this->ArchiveType == 'Yearly') {
                 $year = $date->FormatI18N("%Y");
                 $month = null;
                 $title = $year;
             } else {
                 $year = $date->FormatI18N("%Y");
                 $month = $date->FormatI18N("%m");
                 $title = $date->FormatI18N("%B %Y");
             }
             $archive->push(new ArrayData(array('Title' => $title, 'Link' => Controller::join_links($this->Blog()->Link('archive'), $year, $month))));
         }
     }
     return $archive;
 }
开发者ID:sunnysideup,项目名称:silverstripe-blog,代码行数:39,代码来源:BlogArchiveWidget.php

示例5: testDateNow

 public function testDateNow()
 {
     try {
         Date::create('now');
     } catch (WrongArgumentException $e) {
         $this->fail($e->getMessage());
     }
 }
开发者ID:rero26,项目名称:onphp-framework,代码行数:8,代码来源:TimestampTest.class.php

示例6: testGetDayOfWeek

  function testGetDayOfWeek()
  {
    $date = Date ::create($year = 2005, $month = 1, $day=20, $hour=10, $minute=15, $second=30);

    $formated_date = $date->getDayOfWeek();

    $expected = 'Thursday';
    $this->assertEqual($formated_date, 4);
  }
开发者ID:BackupTheBerlios,项目名称:limb-svn,代码行数:9,代码来源:DateTest.class.php

示例7: __construct

 public function __construct($startDate = null, $holidayArray = array())
 {
     if ($startDate) {
         $this->startDate = $startDate;
     } else {
         $this->startDate = Date::create();
     }
     $this->holidays = $holidayArray;
 }
开发者ID:helpfulrobot,项目名称:danae-miller-clendon-silverstripe-roster,代码行数:9,代码来源:RosterGridFieldTitleHeader.php

示例8: testDialectStringObjects

 public function testDialectStringObjects()
 {
     $criteria = Criteria::create(TestUser::dao())->setProjection(Projection::property('id'))->add(Expression::gt('registered', Date::create('2011-01-01')));
     $this->assertEquals($criteria->toDialectString(ImaginaryDialect::me()), 'SELECT test_user.id FROM test_user WHERE (test_user.registered > 2011-01-01)');
     $criteria = Criteria::create(TestUserWithContactExtended::dao())->setProjection(Projection::property('contactExt.city.id', 'cityId'))->add(Expression::eq('contactExt.city', TestCity::create()->setId(22)));
     $this->assertEquals($criteria->toDialectString(ImaginaryDialect::me()), 'SELECT test_user_with_contact_extended.city_id AS cityId FROM test_user_with_contact_extended WHERE (test_user_with_contact_extended.city_id = 22)');
     $cityList = array(TestCity::create()->setId(3), TestCity::create()->setId(44));
     $criteria = Criteria::create(TestUser::dao())->setProjection(Projection::property('id'))->add(Expression::in('city', $cityList));
     $this->assertEquals($criteria->toDialectString(ImaginaryDialect::me()), 'SELECT test_user.id FROM test_user WHERE (test_user.city_id IN (3, 44))');
 }
开发者ID:rero26,项目名称:onphp-framework,代码行数:10,代码来源:CriteriaTest.class.php

示例9: testSafeValues

 public function testSafeValues()
 {
     $prm = Primitive::date('date');
     $date = Date::create('2005-02-19');
     $prm->import(array('date' => '2005-02-19'));
     $this->assertTrue($prm->isImported());
     $this->assertTrue($prm->getSafeValue() == $date);
     $prm = Primitive::date('date')->setDefault($date);
     $prm->import(array('date' => 'omgEvilInput'));
     $this->assertTrue($prm->isImported());
     $this->assertTrue($prm->getSafeValue() === null);
 }
开发者ID:rero26,项目名称:onphp-framework,代码行数:12,代码来源:FormTest.class.php

示例10: daysTo

 /**
  * @return int
  * @param string|Date|DateTime $date
  */
 public function daysTo($date)
 {
     $from = Date::create($this);
     $to = Date::create($date);
     $from->setTime(0, 0, 0);
     $to->setTime(0, 0, 0);
     $diff = abs($to->format('U') - $from->format('U'));
     if (0 === $diff) {
         return 1;
     }
     $diff = round($diff / self::ONE_DAY);
     return $diff;
 }
开发者ID:studio-v,项目名称:nano,代码行数:17,代码来源:Date.php

示例11: testDefinedFormat

  function testDefinedFormat()
  {
    $date = Date ::create($year = 2005, $month = 1, $day=20, $hour=10, $minute=15, $second=30);

    $template = '<limb:locale:DATE locale="en" date_type="stamp" format="%Y %m %d">'.
                $date->getStamp().
                '</limb:locale:DATE>';

    RegisterTestingTemplate('/limb/locale_date_defined_format.html', $template);

    $page =& new Template('/limb/locale_date_defined_format.html');

    $this->assertEqual($page->capture(), '2005 01 20');
  }
开发者ID:BackupTheBerlios,项目名称:limb-svn,代码行数:14,代码来源:LimbLocaleDateTagTest.class.php

示例12: testGettingDiffDays

 public function testGettingDiffDays()
 {
     $this->assertEquals(1, Date::create('2009-01-01')->daysTo('2009-01-01'));
     $this->assertEquals(1, Date::create('2009-01-01 00:00:00')->daysTo('2009-01-01 23:59:59'));
     $this->assertEquals(1, Date::create('2009-01-01 23:59:59')->daysTo('2009-01-01 23:59:59'));
     $this->assertEquals(1, Date::create('2009-01-01')->daysTo('2009-01-02'));
     $this->assertEquals(1, Date::create('2009-01-01 00:00:00')->daysTo('2009-01-02 23:59:59'));
     $this->assertEquals(1, Date::create('2009-01-01 23:59:59')->daysTo('2009-01-02 23:59:59'));
     $date = Date::create('2009-01-01');
     $test = Date::create('2009-01-01');
     for ($i = 1; $i <= 365; $i++) {
         $test->modify('+1 day');
         $this->assertEquals($i, $date->daysTo($test), $test->toSql('mysql') . ' ' . $date->toSql('mysql'));
     }
 }
开发者ID:studio-v,项目名称:nano,代码行数:15,代码来源:DateTest.php

示例13: makeDatesListByRange

 public static function makeDatesListByRange(DateRange $range, IntervalUnit $unit, $hash = true)
 {
     $date = $unit->truncate($range->getStart());
     if ('Date' == get_class($range->getStart())) {
         $date = Date::create($date->toStamp());
     }
     $dates = array();
     do {
         if ($hash) {
             $dates[$date->toString()] = $date;
         } else {
             $dates[] = $date;
         }
         $date = $date->spawn('+ 1' . $unit->getName());
     } while ($range->getEnd()->toStamp() >= $date->toStamp());
     return $dates;
 }
开发者ID:onphp-framework,项目名称:onphp-framework,代码行数:17,代码来源:DateUtils.class.php

示例14: fromFile

 /**
  * Read from a file
  *
  * @deprecated  Use img.io.MetaDataReader instead
  * @param   io.File file
  * @param   var default default void what should be returned in case no data is found
  * @return  img.util.IptcData
  * @throws  lang.FormatException in case malformed meta data is encountered
  * @throws  lang.ElementNotFoundException in case no meta data is available
  * @throws  img.ImagingException in case reading meta data fails
  */
 public static function fromFile(File $file)
 {
     if (FALSE === getimagesize($file->getURI(), $info)) {
         $e = new ImagingException('Cannot read image information from ' . $file->getURI());
         xp::gc(__FILE__);
         throw $e;
     }
     if (!isset($info['APP13'])) {
         if (func_num_args() > 1) {
             return func_get_arg(1);
         }
         throw new ElementNotFoundException('Cannot get IPTC information from ' . $file->getURI() . ' (no APP13 marker)');
     }
     if (!($iptc = iptcparse($info['APP13']))) {
         throw new FormatException('Cannot parse IPTC information from ' . $file->getURI());
     }
     // Parse creation date
     if (3 == sscanf(@$iptc['2#055'][0], '%4d%2d%d', $year, $month, $day)) {
         $created = Date::create($year, $month, $day, 0, 0, 0);
     } else {
         $created = NULL;
     }
     with($i = new self());
     $i->setTitle(@$iptc['2#005'][0]);
     $i->setUrgency(@$iptc['2#010'][0]);
     $i->setCategory(@$iptc['2#015'][0]);
     $i->setSupplementalCategories(@$iptc['2#020']);
     $i->setKeywords(@$iptc['2#025']);
     $i->setSpecialInstructions(@$iptc['2#040'][0]);
     $i->setDateCreated($created);
     $i->setAuthor(@$iptc['2#080'][0]);
     $i->setAuthorPosition(@$iptc['2#085'][0]);
     $i->setCity(@$iptc['2#090'][0]);
     $i->setState(@$iptc['2#095'][0]);
     $i->setCountry(@$iptc['2#101'][0]);
     $i->setOriginalTransmissionReference(@$iptc['2#103'][0]);
     $i->setHeadline(@$iptc['2#105'][0]);
     $i->setCredit(@$iptc['2#110'][0]);
     $i->setSource(@$iptc['2#115'][0]);
     $i->setCopyrightNotice(@$iptc['2#116'][0]);
     $i->setCaption(@$iptc['2#120'][0]);
     $i->setWriter(@$iptc['2#122'][0]);
     return $i;
 }
开发者ID:melogamepay,项目名称:xp-framework,代码行数:55,代码来源:IptcData.class.php

示例15: castValue

 /**
  * Cast a given value
  *
  * @see     xp://scriptlet.xml.workflow.casters.ParamCaster
  * @param   array value
  * @return  array value
  */
 public function castValue($value)
 {
     $return = array();
     foreach ($value as $k => $v) {
         if ('' === $v) {
             return 'empty';
         }
         $pv = call_user_func(self::$parse, $v);
         if (!is_int($pv['year']) || !is_int($pv['month']) || !is_int($pv['day']) || 0 < $pv['warning_count'] || 0 < $pv['error_count']) {
             return 'invalid';
         }
         try {
             $date = Date::create($pv['year'], $pv['month'], $pv['day'], $pv['hour'], $pv['minute'], $pv['second']);
         } catch (IllegalArgumentException $e) {
             return $e->getMessage();
         }
         $return[$k] = $date;
     }
     return $return;
 }
开发者ID:melogamepay,项目名称:xp-framework,代码行数:27,代码来源:ToDate.class.php


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