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