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


PHP Carbon::diffForHumans方法代码示例

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


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

示例1: getDateAdmissionAttribute

 public function getDateAdmissionAttribute()
 {
     $now = new Carbon();
     $dt = new Carbon($this->created_at);
     $dt->setLocale('es');
     return $dt->diffForHumans($now);
 }
开发者ID:sibasbo,项目名称:sibas,代码行数:7,代码来源:Facultative.php

示例2: get_warnings_object

 public function get_warnings_object()
 {
     //Get the users warnings from the Database
     $warnings = DB::connection('server')->table('warnings')->where('ckey', '=', $this->player_ckey)->where('visible', '=', '1')->get();
     //Transform the timestamps to Ago strings
     foreach ($warnings as $warning) {
         $carbon = new Carbon($warning->time);
         $warning->diff = $carbon->diffForHumans();
     }
     return $warnings;
 }
开发者ID:Aurorastation,项目名称:Web-Interface,代码行数:11,代码来源:PlayerWarning.php

示例3: getDateDiff

 public function getDateDiff()
 {
     $created = new Carbon($this->created_at);
     $now = Carbon::now();
     $difference = $created->diff($now)->days < 1 ? 'today' : $created->diffForHumans($now, true);
     if ($difference == 'today') {
         return $difference;
     }
     return $difference . " ago";
     //$cDate->diffInDays() . " days ago";
 }
开发者ID:gazatem,项目名称:dblogger,代码行数:11,代码来源:Log.php

示例4: date

 public function date($date)
 {
     $created = new Carbon($date);
     $now = Carbon::now();
     $difference = $created->diff($now)->days < 1 ? 'today' : $created->diffForHumans($now);
     $dates = explode(" ", $difference);
     if (count($dates) > 1) {
         if ($dates[1] == "month" or $dates[1] == "months") {
             if ($dates[0] >= 1) {
                 return true;
             }
         } else {
             return false;
         }
     }
     return false;
 }
开发者ID:juan2ramos,项目名称:credito,代码行数:17,代码来源:UploadUserManager.php

示例5: getFilters

 /**
  * Dodatkowe filtry Twig zwiazane z formatowaniem danych uzytkownika
  *
  * @return array
  */
 public function getFilters()
 {
     return [new Twig_SimpleFilter('format_date', function ($dateTime, $diffForHumans = true) {
         $format = Auth::check() ? auth()->user()->date_format : '%Y-%m-%d %H:%M';
         if (!$dateTime instanceof Carbon) {
             $dateTime = new Carbon($dateTime);
         }
         $now = Carbon::now();
         if (!$diffForHumans) {
             return $dateTime->formatLocalized($format);
         } elseif ($dateTime->diffInHours($now) < 1) {
             return $dateTime->diffForHumans(null, true) . ' temu';
         } elseif ($dateTime->isToday()) {
             return 'dziś, ' . $dateTime->format('H:i');
         } elseif ($dateTime->isYesterday()) {
             return 'wczoraj, ' . $dateTime->format('H:i');
         } else {
             return $dateTime->formatLocalized($format);
         }
     }), new Twig_SimpleFilter('timestamp', function ($dateTime) {
         if ($dateTime instanceof Carbon) {
             return $dateTime->getTimestamp();
         } else {
             return strtotime($dateTime);
         }
     })];
 }
开发者ID:furious-programming,项目名称:coyote,代码行数:32,代码来源:User.php

示例6: Carbon

<?php

require_once 'vendor/autoload.php';
use Carbon\Carbon;
use Citco\Carbon as CitcoCarbon;
use CarbonExt\FiscalYear\Calculator;
// Object Instantiation
$brisbane = new Carbon('2015-12-01', 'Australia/Brisbane');
$newYorkCity = new Carbon('2015-12-01', 'America/New_York');
$dtBerlin = new Carbon('2015-12-01', 'Europe/Berlin');
$outputString = "Time difference between %s & %s: %s hours.\n";
// Date difference
printf($outputString, "Berlin", "Brisbane, Australia", $dtBerlin->diffInHours($brisbane, false));
printf($outputString, "Berlin", "New York City, America", $dtBerlin->diffInHours($newYorkCity, false));
$septEighteen2014 = Carbon::createFromDate(2014, 9, 18, $dtBerlin->getTimezone());
printf("difference between now and %s in \n\thours: %d, \n\tdays: %d, \n\tweeks: %d, \n\tweekend days: %d, \n\tweek days: %s, \n\thuman readable: %s\n", $septEighteen2014->toFormattedDateString(), $dtBerlin->diffInHours($septEighteen2014), $dtBerlin->diffInDays($septEighteen2014), $dtBerlin->diffInWeeks($septEighteen2014), $dtBerlin->diffInWeekendDays($septEighteen2014), $dtBerlin->diffInWeekDays($septEighteen2014), $dtBerlin->diffForHumans($septEighteen2014));
// Date formatting
echo $dtBerlin->toDateString() . "\n";
echo $dtBerlin->toFormattedDateString() . "\n";
echo $dtBerlin->toTimeString() . "\n";
echo $dtBerlin->toDateTimeString() . "\n";
echo $dtBerlin->toDayDateTimeString() . "\n";
echo $dtBerlin->toRfc1036String() . "\n";
echo $dtBerlin->toAtomString() . "\n";
echo $dtBerlin->toCookieString() . "\n";
echo $dtBerlin->toRssString() . "\n";
$dtBerlin->setToStringFormat('l jS \\of F Y');
echo $dtBerlin . "\n";
echo (int) $dtBerlin->isLeapYear() . "\n";
// is* range of functions test
printf("Is yesterday? %s\n", $dtBerlin->isYesterday() ? "yes" : "no");
开发者ID:settermjd,项目名称:carbon-experiments,代码行数:31,代码来源:index.php

示例7: getLastUpdatedRelative

 public function getLastUpdatedRelative()
 {
     $date = new Carbon($this->updated_at);
     return $date->diffForHumans();
 }
开发者ID:GMSteuart,项目名称:PandaLove,代码行数:5,代码来源:Character.php

示例8: ago

 public function ago(Carbon $other = null, $absolute = false)
 {
     $diff = parent::diffForHumans($other, $absolute);
     $pattern = array("years", "months", "days", "weeks", "hours", "minutes", "seconds", "year", "month", "day", "week", "hour", "minute", "second", "from now", "ago", "after", "before");
     $replace = array("سال", "ماه", "روز", "هقته", "ساعت", "دقیقه", "ثانیه", "سال", "ماه", "روز", "هقته", "ساعت", "دقیقه", "ثانیه", "از الان", "پیش", "بعد", "قبل");
     return str_replace($pattern, $replace, $diff);
 }
开发者ID:persiscms,项目名称:Solar-Carbon,代码行数:7,代码来源:jDate.php

示例9: Carbon

                            </a>
                        </li>
                        <li>
                            <a href="#" title="" data-toggle="tooltip" data-container="body" data-original-title="0 nouveau badge">
                                <i class="fa fa-trophy"></i>
                            </a>
                        </li>
                    </ul>
                    <div class="last-visit">
                        <p><b>Last visit :</b></p>
                        <p class="text-center">
                            About
                            <?php 
$last = new Carbon(Auth::user()->last_login);
$now = Carbon::now();
echo $last->diffForHumans($now, true);
?>
                            ago
                        </p>
                    </div>
                </div>
            </div>
            <div class="col-sm-8 col-xs-12">
                <div class="block-group scheme-blue">
                    <div class="block block-sm hidden-xs">
                        <div class="inline-left color-white"><strong>Level progress:</strong></div>
                        <div class="inline-full">
                            <div class="progress progress-sm">
                                <div class="progress-bar" role="progressbar" style="width: {{$level['percent']}}%">
                                </div>
                            </div>
开发者ID:prudywsh,项目名称:tpe,代码行数:31,代码来源:loggedin.blade.php

示例10: switch

    switch ($c) {
        case 'f':
            $url = new Facebook();
            return $url->getLoginUrl();
        case 'g':
            $client = new Google_Client();
            $auth = new GoogleModel($client);
            return $auth->getAuthUrl();
    }
}, 'is_loggedin' => function () {
    $u = new User();
    return $u->isLoggedIn();
}, 'time' => function ($time) {
    $t = new Carbon($time);
    return $t->toRfc850String();
}, 'readable_time' => function ($time) {
    $t = new Carbon($time);
    return $t->diffForHumans();
}, 'strip' => function ($string) {
    // strip tags to avoid breaking any html
    $string = strip_tags($string);
    if (strlen($string) > 500) {
        // truncate string
        $stringCut = substr($string, 0, 500);
        // make sure it ends in a word so assassinate doesn't become ass...
        $string = substr($stringCut, 0, strrpos($stringCut, ' '));
    }
    return nl2br($string);
}], 'filters' => ['e' => function ($str) {
    return Func::escape($str);
}]];
开发者ID:taekunger,项目名称:kodekit,代码行数:31,代码来源:twig.php

示例11: timeDifference

 /**
  * @param Carbon    /Carbon $created string
  * @param $absolute bool
  *
  * @return string
  * */
 static function timeDifference($created, $absolute = true)
 {
     $carbon = new Carbon();
     return $carbon->diffForHumans($created, $absolute);
 }
开发者ID:Dimimo,项目名称:Booklet,代码行数:11,代码来源:MyHelper.php

示例12: setDateTime

 private function setDateTime(Carbon $datetime)
 {
     return $datetime->year > 0 ? $datetime . "<br/><small>(" . $datetime->diffForHumans() . ")</small>" : "-";
 }
开发者ID:kravn,项目名称:TTG-CMS,代码行数:4,代码来源:DataTableController.php

示例13: getDateDiffForHumans

 public function getDateDiffForHumans($field)
 {
     $carbon = new Carbon($this->{$field});
     return $carbon->diffForHumans();
 }
开发者ID:sorora,项目名称:bms,代码行数:5,代码来源:Post.php

示例14: StandardDateHTML

 public static function StandardDateHTML(Carbon $date, $includetime = false, $comparetonow = false, $includeicon = false)
 {
     $output = '';
     $close = clone $date;
     $close = $close->addDays(-5);
     if ($comparetonow) {
         $now = Carbon::today();
         if ($date <= $now) {
             $output .= '<span class="text-danger">';
         } elseif ($close <= $now) {
             $output .= '<span class="text-warning">';
         } else {
             $output .= '<span>';
         }
     } else {
         $output .= '<span>';
     }
     if ($includeicon) {
         $output .= '<i class="fa fa-clock-o"></i> ';
     }
     $output .= $date->diffForHumans();
     $output .= '<br/>';
     if ($includetime) {
         $output .= '&nbsp;&nbsp;&nbsp; <small>( ' . $date->format('d M Y h:s') . ' )</small>';
     } else {
         $output .= '&nbsp;&nbsp;&nbsp; <small>( ' . $date->format('d M Y') . ' )</small>';
     }
     $output .= '</span>';
     return $output;
 }
开发者ID:SlipperyPenguine,项目名称:tracker,代码行数:30,代码来源:HtmlFormating.php

示例15: sendAt

 /**
  *
  *Get the message sent time in human readable form
  */
 public function sendAt()
 {
     $myTime = new Carbon($this->created_at);
     return $myTime->diffForHumans();
 }
开发者ID:razikallayi,项目名称:peaceschools,代码行数:9,代码来源:Message.php


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