美文网首页
Carbon API解读

Carbon API解读

作者: MakingChoice | 来源:发表于2016-07-27 10:09 被阅读97次
use Carbon\Carbon;

printf("Right now is %s", Carbon::now()->toDateTimeString());//当前时间
printf("Right now in Vancouver is %s", Carbon::now('America/Vancouver'));  //implicit __toString() 设置时间位置
$tomorrow = Carbon::now()->addDay();//明天
$lastWeek = Carbon::now()->subWeek();//上周时间
$nextSummerOlympics = Carbon::createFromDate(2012)->addYears(4);//四年之后的时间
$officialDate = Carbon::now()->toRfc2822String();//官方时间
$howOldAmI = Carbon::createFromDate(1975, 5, 21)->age;//从设定的时间到
$noonTodayLondonTime = Carbon::createFromTime(12, 0, 0, 'Europe/London');//设置从某个地点开始的某个时间间隔
$worldWillEnd = Carbon::createFromDate(2012, 12, 21, 'GMT');//设置时间点
// Don't really want to die so mock now
Carbon::setTestNow(Carbon::createFromDate(2000, 1, 1));
// comparisons are always done in UTC
if (Carbon::now()->gte($worldWillEnd)) {
    die();
}
// Phew! Return to normal behaviour
Carbon::setTestNow();
if (Carbon::now()->isWeekend()) {
    echo 'Party!';
}
echo Carbon::now()->subMinutes(2)->diffForHumans(); // '2 minutes ago'
// ... but also does 'from now', 'after' and 'before'
// rolling up to seconds, minutes, hours, days, months, years
$daysSinceEpoch = Carbon::createFromTimestamp(0)->diffInDays();

更多API在这里

相关文章

网友评论

      本文标题:Carbon API解读

      本文链接:https://www.haomeiwen.com/subject/gldojttx.html