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


PHP DateTime::Format方法代码示例

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


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

示例1: updateCMSFields

 public function updateCMSFields(FieldList $fields)
 {
     $fields->removeByName('LastSignificantChange');
     $fields->removeByName('ChangeDescription');
     if ($this->owner->LastSignificantChange !== NULL) {
         $dateTime = new DateTime($this->owner->LastSignificantChange);
         //Put these fields on the top of the First Tab's form
         $fields->first()->Tabs()->first()->getChildren()->unshift(LabelField::create("infoLastSignificantChange", "<strong>Last Significant change was at: " . "{$dateTime->Format('d/m/Y H:i')}</strong>"));
         $fields->insertAfter(CheckboxField::create("isSignificantChange", "CLEAR Last Significant change: {$dateTime->Format('d/m/Y H:i')}")->setDescription('Check and save this Record again to clear the Last Significant change date.')->setValue(FALSE), 'infoLastSignificantChange');
         $fields->insertAfter(TextField::create('ChangeDescription', 'Description of Changes')->setDescription('This is an automatically generated list of changes to important fields.'), 'isSignificantChange');
     }
 }
开发者ID:helpfulrobot,项目名称:silverstripe-australia-datachange-tracker,代码行数:12,代码来源:SignificantChangeRecordable.php

示例2: LatestTweetsList

 public function LatestTweetsList($limit = '5')
 {
     $conf = SiteConfig::current_site_config();
     if (empty($conf->TwitterName) || empty($conf->TwitterConsumerKey) || empty($conf->TwitterConsumerSecret) || empty($conf->TwitterAccessToken) || empty($conf->TwitterAccessTokenSecret)) {
         return new ArrayList();
     }
     $cache = SS_Cache::factory('LatestTweets_cache');
     if (!($results = unserialize($cache->load(__FUNCTION__)))) {
         $results = new ArrayList();
         require_once dirname(__FILE__) . '/tmhOAuth/tmhOAuth.php';
         require_once dirname(__FILE__) . '/tmhOAuth/tmhUtilities.php';
         $tmhOAuth = new tmhOAuth(array('consumer_key' => $conf->TwitterConsumerKey, 'consumer_secret' => $conf->TwitterConsumerSecret, 'user_token' => $conf->TwitterAccessToken, 'user_secret' => $conf->TwitterAccessTokenSecret, 'curl_ssl_verifypeer' => false));
         $code = $tmhOAuth->request('GET', $tmhOAuth->url('1.1/statuses/user_timeline'), array('screen_name' => $conf->TwitterName, 'count' => $limit));
         $tweets = $tmhOAuth->response['response'];
         $json = new JSONDataFormatter();
         if (($arr = $json->convertStringToArray($tweets)) && is_array($arr) && isset($arr[0]['text'])) {
             foreach ($arr as $tweet) {
                 try {
                     $here = new DateTime(SS_Datetime::now()->getValue());
                     $there = new DateTime($tweet['created_at']);
                     $there->setTimezone($here->getTimezone());
                     $date = $there->Format('Y-m-d H:i:s');
                 } catch (Exception $e) {
                     $date = 0;
                 }
                 $results->push(new ArrayData(array('Text' => nl2br(tmhUtilities::entify_with_options($tweet, array('target' => '_blank'))), 'Date' => SS_Datetime::create_field('SS_Datetime', $date))));
             }
         }
         $cache->save(serialize($results), __FUNCTION__);
     }
     return $results;
 }
开发者ID:unisolutions,项目名称:silverstripe-latesttweets,代码行数:32,代码来源:LaTw_Page_Controller_Extension.php

示例3: setValue

 public function setValue($value, $record = null)
 {
     if ($value === false || $value === null || is_string($value) && !strlen($value)) {
         // don't try to evaluate empty values with strtotime() below, as it returns "1970-01-01" when it should be
         // saved as NULL in database
         $this->value = null;
         return;
     }
     // Default to NZ date format - strtotime expects a US date
     if (preg_match('#^([0-9]+)/([0-9]+)/([0-9]+)$#', $value, $parts)) {
         $value = "{$parts['2']}/{$parts['1']}/{$parts['3']}";
     }
     if (is_numeric($value)) {
         $this->value = date('Y-m-d H:i:s', $value);
     } elseif (is_string($value)) {
         // $this->value = date('Y-m-d H:i:s', strtotime($value));
         try {
             $date = new DateTime($value);
             $this->value = $date->Format('Y-m-d H:i:s');
             return;
         } catch (Exception $e) {
             $this->value = null;
             return;
         }
     }
 }
开发者ID:jareddreyer,项目名称:catalogue,代码行数:26,代码来源:Datetime.php

示例4: Format

 /**
  * Returns the date in the raw SQL-format specific to a given timezone passed from the Member class, e.g. “2006-01-18 16:32:04”
  */
 public function Format($format)
 {
     if ($this->value) {
         $date = new DateTime($this->value);
         //if the current user has set a timezone that is not the default then use that
         $member = $this->getCurrentCachedUser();
         if ($member && $member->exists() && $member->Timezone && $member->Timezone != date_default_timezone_get()) {
             $date->setTimezone(new DateTimeZone($member->Timezone));
         }
         return $date->Format($format);
     }
 }
开发者ID:silverstripe,项目名称:deploynaut,代码行数:15,代码来源:SS_Datetimezone.php

示例5: converterGetData

function converterGetData()
{
    global $fh;
    
    $line = fgets($fh);
    if($line === false)
    {
        return false;
    }
    
    $la = preg_split("/(\s*\|\s*)/", $line);
    $date = substr($la[0],1);

    $d = new DateTime($date);
    $date = $d->Format('d.m.Y H:i:s');
    $day = $d->Format('d');
    $hour = $d->Format('H');

    $res = array();
    $res['src'] = $date."\t".$la[3]."\t".$la[1]."\t".($la[1])."\t".$la[2]."\t".($la[2])."\tA0\tB0\t0\t".$la[3]."\t0\n";
    $res['gibs'] = explode("\t", $res['src']);
    return $res;

}
开发者ID:nolka,项目名称:logconverter,代码行数:24,代码来源:geyservice.php

示例6: Format

 /**
  * Return the date using a particular formatting string.
  *
  * @param string $format Format code string. e.g. "d M Y" (see http://php.net/date)
  * @param mixed $value Value to format
  * @return string The date in the requested format
  */
 public static function Format($format, $value)
 {
     if ($value) {
         // Use current locale if different from configured i18n locale
         $i18nLocale = $currentLocale = i18n::get_locale();
         if (class_exists("Translatable")) {
             $currentLocale = Translatable::get_current_locale();
         }
         if (self::$locale) {
             $currentLocale = self::$locale;
         }
         if ($currentLocale != $i18nLocale) {
             i18n::set_locale($currentLocale);
         }
         // Set date
         $date = new DateTime($value);
         // Flag escaped chars (or there will be problems with formats like "F\D")
         $escapeId = '-' . time() . '-';
         $format = str_replace('\\', $escapeId . '\\', $format);
         // Get formatted date
         $dateStr = $date->Format($format);
         // Translate all word-strings
         $dateStr = preg_replace_callback("/([a-z]*)([^a-z])/isU", function ($m) {
             if (empty($m[1])) {
                 // Nothing to translate
                 return $m[0];
             }
             return _t('LocalDate.' . $m[1], $m[1]) . $m[2];
         }, $dateStr . ' ');
         // Remove escape flags
         $dateStr = str_replace($escapeId, '', $dateStr);
         // Reset i18n locale
         if ($currentLocale != $i18nLocale) {
             i18n::set_locale($i18nLocale);
         }
         // Return translated date string
         return substr($dateStr, 0, strlen($dateStr) - 1);
     }
 }
开发者ID:helpfulrobot,项目名称:richardsjoqvist-silverstripe-localdate,代码行数:46,代码来源:LocalDateHelper.php

示例7: adodb_date

/**
	Return formatted date based on timestamp $d
*/
function adodb_date($fmt, $d = false, $is_gmt = false)
{
    static $daylight;
    global $ADODB_DATETIME_CLASS;
    if ($d === false) {
        return $is_gmt ? @gmdate($fmt) : @date($fmt);
    }
    if (!defined('ADODB_TEST_DATES')) {
        if (abs($d) <= 0x7fffffff) {
            // check if number in 32-bit signed range
            if (!defined('ADODB_NO_NEGATIVE_TS') || $d >= 0) {
                // if windows, must be +ve integer
                return $is_gmt ? @gmdate($fmt, $d) : @date($fmt, $d);
            }
        }
    }
    $_day_power = 86400;
    $arr = _adodb_getdate($d, true, $is_gmt);
    if (!isset($daylight)) {
        $daylight = function_exists('adodb_daylight_sv');
    }
    if ($daylight) {
        adodb_daylight_sv($arr, $is_gmt);
    }
    $year = $arr['year'];
    $month = $arr['mon'];
    $day = $arr['mday'];
    $hour = $arr['hours'];
    $min = $arr['minutes'];
    $secs = $arr['seconds'];
    $max = strlen($fmt);
    $dates = '';
    $isphp5 = PHP_VERSION >= 5;
    /*
    	at this point, we have the following integer vars to manipulate:
    	$year, $month, $day, $hour, $min, $secs
    */
    for ($i = 0; $i < $max; $i++) {
        switch ($fmt[$i]) {
            case 'T':
                if ($ADODB_DATETIME_CLASS) {
                    $dt = new DateTime();
                    $dt->SetDate($year, $month, $day);
                    $dates .= $dt->Format('T');
                } else {
                    $dates .= date('T');
                }
                break;
                // YEAR
            // YEAR
            case 'L':
                $dates .= $arr['leap'] ? '1' : '0';
                break;
            case 'r':
                // Thu, 21 Dec 2000 16:01:07 +0200
                // 4.3.11 uses '04 Jun 2004'
                // 4.3.8 uses  ' 4 Jun 2004'
                $dates .= gmdate('D', $_day_power * (3 + adodb_dow($year, $month, $day))) . ', ' . ($day < 10 ? '0' . $day : $day) . ' ' . date('M', mktime(0, 0, 0, $month, 2, 1971)) . ' ' . $year . ' ';
                if ($hour < 10) {
                    $dates .= '0' . $hour;
                } else {
                    $dates .= $hour;
                }
                if ($min < 10) {
                    $dates .= ':0' . $min;
                } else {
                    $dates .= ':' . $min;
                }
                if ($secs < 10) {
                    $dates .= ':0' . $secs;
                } else {
                    $dates .= ':' . $secs;
                }
                $gmt = adodb_get_gmt_diff($year, $month, $day);
                $dates .= ' ' . adodb_tz_offset($gmt, $isphp5);
                break;
            case 'Y':
                $dates .= $year;
                break;
            case 'y':
                $dates .= substr($year, strlen($year) - 2, 2);
                break;
                // MONTH
            // MONTH
            case 'm':
                if ($month < 10) {
                    $dates .= '0' . $month;
                } else {
                    $dates .= $month;
                }
                break;
            case 'Q':
                $dates .= $month + 3 >> 2;
                break;
            case 'n':
                $dates .= $month;
                break;
//.........这里部分代码省略.........
开发者ID:dasatti,项目名称:dashboard,代码行数:101,代码来源:adodb-time.inc.php

示例8: Format

 /**
  * Return the date using a particular formatting string.
  *
  * @param string $format Format code string. e.g. "d M Y" (see http://php.net/date)
  * @return string The date in the requested format
  */
 public function Format($format)
 {
     if ($this->value) {
         $date = new DateTime($this->value);
         return $date->Format($format);
     }
 }
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:13,代码来源:Date.php

示例9: set_post_content_34

function set_post_content_34($entry, $form)
{
    // Create flatterbox post object
    //Get the current user info to insert into flatterbox information
    $current_user = wp_get_current_user();
    $current_user_name = $current_user->user_login;
    //Set up the flatterbox information to insert
    $my_flatterbox = array('post_title' => $entry["1"] . '\'s ' . $entry["26"] . ' Flatterbox', 'post_type' => 'flatterboxes', 'post_content' => '', 'post_status' => 'publish', 'post_author' => get_current_user_id());
    // Insert the post into the database
    if (!isset($_SESSION["new_flatterbox_id"])) {
        $new_post_id = wp_insert_post($my_flatterbox);
        $newpid = $new_post_id;
    } else {
        $my_flatterbox = array('ID' => $_SESSION["new_flatterbox_id"], 'post_title' => $entry["1"] . '\'s ' . $entry["26"] . ' Flatterbox', 'post_content' => '');
        wp_update_post($my_flatterbox);
        // To update the title
        $newpid = $_SESSION["new_flatterbox_id"];
    }
    $_SESSION["occassion_name"] = $entry["26"];
    wp_set_object_terms($newpid, $entry["26"], 'flatterbox_type', 0);
    //Convert date to ACF's format
    $date = new DateTime($entry["2"]);
    $newdate = $date->Format(Ymd);
    $boxtheme = '';
    switch ($entry["26"]) {
        case 'Birthday':
            $boxtheme = $entry["27"];
            break;
        case 'Anniversary':
            $boxtheme = $entry["28"];
            break;
        case 'Military Gift':
            $boxtheme = $entry["53"];
            break;
        case 'Get Well':
            $boxtheme = $entry["52"];
            break;
        case 'Bar/Bat Mizvah':
            $boxtheme = $entry["51"];
            break;
        case 'New Baby/Parents':
            $boxtheme = $entry["50"];
            break;
        case 'Engagement':
            $boxtheme = $entry["49"];
            break;
        case 'Wedding':
            $boxtheme = $entry["48"];
            break;
        case 'Graduation':
            $boxtheme = $entry["47"];
            break;
        case 'Bridal Shower':
            $boxtheme = $entry["46"];
            break;
        case "Boss' Gift":
            $boxtheme = $entry["45"];
            break;
        case 'Holiday':
            $boxtheme = $entry["44"];
            break;
        case "Valentine's Day":
            $boxtheme = $entry["43"];
            break;
        case "Father's Day":
            $boxtheme = $entry["42"];
            break;
        case 'Sweet 16':
            $boxtheme = $entry["41"];
            break;
        case 'Love You Because...':
            $boxtheme = $entry["40"];
            break;
        case 'Retirement':
            $boxtheme = $entry["39"];
            break;
        case 'Hanukkah':
            $boxtheme = $entry["38"];
            break;
        case "Mother's Day":
            $boxtheme = $entry["37"];
            break;
        case 'Funeral':
            $boxtheme = $entry["36"];
            break;
        case 'New Year Encouragement':
            $boxtheme = $entry["80"];
            break;
        case 'Just Because...':
            $boxtheme = $entry["34"];
            break;
        case 'Divorce Encouragement':
            $boxtheme = $entry["33"];
            break;
        case 'Corporate Meeting':
            $boxtheme = $entry["32"];
            break;
        case "Teacher's Gift":
            $boxtheme = $entry["31"];
            break;
//.........这里部分代码省略.........
开发者ID:avijitdeb,项目名称:flatterbox.com,代码行数:101,代码来源:functions.php

示例10: dateFilter

 /**
  *	Request media page children from the filtered date.
  */
 public function dateFilter()
 {
     // Apply the from date filter.
     $request = $this->getRequest();
     $from = $request->getVar('from');
     $link = $this->Link();
     $separator = '?';
     if ($from) {
         // Determine the formatted URL to represent the request filter.
         $date = new DateTime($from);
         $link .= $date->Format('Y/m/d/');
     }
     // Preserve the category/tag filters if they exist.
     $category = $request->getVar('category');
     $tag = $request->getVar('tag');
     if ($category) {
         $link = HTTP::setGetVar('category', $category, $link, $separator);
         $separator = '&';
     }
     if ($tag) {
         $link = HTTP::setGetVar('tag', $tag, $link, $separator);
     }
     // Allow extension customisation.
     $this->extend('updateFilter', $link);
     // Request the filtered paginated children.
     return $this->redirect($link);
 }
开发者ID:helpfulrobot,项目名称:nglasl-silverstripe-mediawesome,代码行数:30,代码来源:MediaHolder.php

示例11: testGetFirstWhenConfigValidShouldGetTheFirstCharge

 /**
  * @group test
  * The get first charge test method.
  */
 public function testGetFirstWhenConfigValidShouldGetTheFirstCharge()
 {
     date_default_timezone_set("UTC");
     $testConfig = new TestServicesConfig();
     $chargeSvc = new HpsCreditService($testConfig->ValidMultiUseConfig());
     $dateFormat = 'Y-m-d\\TH:i:s.00\\Z';
     $dateMinus10 = new DateTime();
     $dateMinus10->sub(new DateInterval('PT10H'));
     $dateMinus10Utc = gmdate($dateFormat, $dateMinus10->Format('U'));
     $nowUtc = gmdate($dateFormat);
     $items = $chargeSvc->ListTransactions($dateMinus10Utc, $nowUtc, "CreditSale");
     // HpsTransactionType::Capture
     $this->assertTrue(0 != count($items));
     $charge0 = $items[0]->transactionId;
     $charge1 = $items[1]->transactionId;
     $this->assertNotNull($charge0);
     $this->assertNotNull($charge1);
     $this->assertNotEquals($charge0, $charge1);
 }
开发者ID:bericonsulting,项目名称:heartland-php,代码行数:23,代码来源:GeneralTest.php

示例12: isAffichable

function isAffichable($abs, $date, $eleve)
{
    $creneau_col = EdtCreneauPeer::retrieveAllEdtCreneauxOrderByTime();
    $test_ouverture = false;
    foreach ($creneau_col as $creneau) {
        $datedebutabs = explode(" ", $abs->getDebutAbs());
        $dt_date_debut_abs = new DateTime($datedebutabs[0]);
        $heure_debut = explode(":", $datedebutabs[1]);
        $dt_date_debut_abs->setTime($heure_debut[0], $heure_debut[1], $heure_debut[2]);
        $tab_heure = explode(":", $creneau->getHeuredebutDefiniePeriode());
        $date->setTime($tab_heure[0], $tab_heure[1], $tab_heure[2]);
        //on verifie si le creneau est ouvert et s'il est posterieur au debut de l'absence
        if ($date->Format('U') > $dt_date_debut_abs->Format('U') && EdtHelper::isEtablissementOuvert($date)) {
            $test_ouverture = true;
        }
    }
    if ($test_ouverture && $abs->getManquementObligationPresence()) {
        return true;
    } else {
        return false;
    }
}
开发者ID:alhousseyni,项目名称:gepi,代码行数:22,代码来源:bilan_parent.php

示例13: testListTransactions

 public function testListTransactions()
 {
     date_default_timezone_set("UTC");
     $config = TestServicesConfig::validMultiUseConfig();
     $dateFormat = 'Y-m-d\\TH:i:s.00\\Z';
     $dateMinus10 = new DateTime();
     $dateMinus10->sub(new DateInterval('PT10H'));
     $dateMinus10Utc = gmdate($dateFormat, $dateMinus10->Format('U'));
     $nowUtc = gmdate($dateFormat);
     $transactions = $this->service->listTransactions()->withStartDate($dateMinus10Utc)->withEndDate($nowUtc)->withFilterBy("CreditSale")->execute();
     $this->assertTrue(0 != count($transactions));
     $charge0 = $transactions[0]->originalTransactionId;
     $charge1 = $transactions[1]->originalTransactionId;
     $this->assertNotNull($charge0);
     $this->assertNotNull($charge1);
 }
开发者ID:cdrive,项目名称:heartland-php,代码行数:16,代码来源:FluentCreditTest.php

示例14: DateTime

        $delivery = $date->Format("m/d/Y");
    } else {
        $delivery = '';
    }
    ?>
	jQuery("#input_<?php 
    echo $iForm;
    ?>
_2").val('<?php 
    echo $delivery;
    ?>
');
	<?php 
    if (strlen($_GET['finalize']) > 0) {
        $date = new DateTime($_GET['finalize']);
        $sentimentdate = $date->Format("m/d/Y");
    } else {
        $sentimentdate = '';
    }
    ?>
	
	jQuery("#input_<?php 
    echo $iForm;
    ?>
_54").val('<?php 
    echo $sentimentdate;
    ?>
');
	jQuery("#input_<?php 
    echo $iForm;
    ?>
开发者ID:avijitdeb,项目名称:flatterbox.com,代码行数:31,代码来源:page-step3-options.php

示例15: discardJob

 /**
  * Abort this job, potentially rescheduling a replacement if there is still work to do
  */
 protected function discardJob()
 {
     $this->skipped = true;
     // If we do not have dirty records, then assume that these dirty records were committed
     // already this request (but probably another job), so we don't need to commit anything else.
     // This could occur if we completed multiple searchupdate jobs in a prior request, and
     // we only need one commit job to commit all of them in the current request.
     if (empty(static::$dirty_indexes)) {
         $this->addMessage("Indexing already completed this request: Discarding this job");
         return;
     }
     // If any commit has run, but some (or all) indexes are un-comitted, we must re-schedule this task.
     // This could occur if we completed a searchupdate job in a prior request, as well as in
     // the current request
     $cooldown = Config::inst()->get(__CLASS__, 'cooldown');
     $now = new DateTime(SS_Datetime::now()->getValue());
     $now->add(new DateInterval('PT' . $cooldown . 'S'));
     $runat = $now->Format('Y-m-d H:i:s');
     $this->addMessage("Indexing already run this request, but incomplete. Re-scheduling for {$runat}");
     // Queue after the given cooldown
     static::queue(false, $runat);
 }
开发者ID:helpfulrobot,项目名称:silverstripe-fulltextsearch,代码行数:25,代码来源:SearchUpdateCommitJobProcessor.php


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