本文整理汇总了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);
}
示例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;
}
示例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";
}
示例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;
}
示例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);
}
})];
}
示例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");
示例7: getLastUpdatedRelative
public function getLastUpdatedRelative()
{
$date = new Carbon($this->updated_at);
return $date->diffForHumans();
}
示例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);
}
示例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>
示例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);
}]];
示例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);
}
示例12: setDateTime
private function setDateTime(Carbon $datetime)
{
return $datetime->year > 0 ? $datetime . "<br/><small>(" . $datetime->diffForHumans() . ")</small>" : "-";
}
示例13: getDateDiffForHumans
public function getDateDiffForHumans($field)
{
$carbon = new Carbon($this->{$field});
return $carbon->diffForHumans();
}
示例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 .= ' <small>( ' . $date->format('d M Y h:s') . ' )</small>';
} else {
$output .= ' <small>( ' . $date->format('d M Y') . ' )</small>';
}
$output .= '</span>';
return $output;
}
示例15: sendAt
/**
*
*Get the message sent time in human readable form
*/
public function sendAt()
{
$myTime = new Carbon($this->created_at);
return $myTime->diffForHumans();
}