【laravel5】Carbon类

1、https://blog.csdn.net/zhezhebie/article/details/79386051

toDateString() ---输出格式为:2018-06-07
toFormattedDateString() ---输出格式为:Jun 7, 2018
toTimeString() ---输出格式为:07:39:02
toDateTimeString() ---输出格式为:2018-06-07 07:39:02
toDayDateTimeString() ---输出格式为:Thu, Jun 7, 2018 7:39 AM
toAtomString() ---输出格式为:2018-06-07T07:39:02+00:00
toCookieString() ---输出格式为:Thursday, 07-Jun-2018 07:39:02 UTC
toIso8601String() ---输出格式为:2018-06-07T07:39:02+00:00
toRfc822String() ---输出格式为:Thu, 07 Jun 18 07:39:02 +0000
toIso8601ZuluString() ---输出格式为:2018-06-07T07:39:02Z
toRfc850String() ---输出格式为:Thursday, 07-Jun-18 07:39:02 UTC
toRfc1036String() ---输出格式为:Thu, 07 Jun 18 07:39:02 +0000
toRfc1123String() ---输出格式为:Thu, 07 Jun 2018 07:39:02 +0000
toRfc2822String() ---输出格式为:Thu, 07 Jun 2018 07:39:02 +0000
toRfc3339String() ---输出格式为:2018-06-07T07:39:02+00:00
toRssString() ---输出格式为:Thu, 07 Jun 2018 07:39:02 +0000
toW3cString() ---输出格式为:2018-06-07T07:39:02+00:00
toRfc7231String() ---输出格式为:Thu, 07 Jun 2018 07:39:02 GMT

 

2、https://www.cnblogs.com/huangshoushi/p/6625981.html

<?php
use Carbon\Carbon;

$now = Carbon::now();
echo $now;                               // 2015-03-26 00:36:47
$today = Carbon::today();
echo $today;                             // 2015-03-26 00:00:00
$tomorrow = Carbon::tomorrow('Europe/London');
echo $tomorrow;                          // 2015-03-27 00:00:00
$yesterday = Carbon::yesterday();
echo $yesterday;                         // 2015-03-25 00:00:00

$carbon = Carbon::now()->XXX();
toDateString() ---输出格式为:2018-06-07
toTimeString() ---输出格式为:07:39:02
toDateTimeString() ---输出格式为:2018-06-07 07:39:02

<?php

use Carbon\Carbon;

$dt = Carbon::parse('2012-9-5 23:26:11.123789');

// 取的指定時間資料的資訊(整數)
var_dump($dt->year);                                         // int(2012)
var_dump($dt->month);                                        // int(9)
var_dump($dt->day);                                          // int(5)
var_dump($dt->hour);                                         // int(23)
var_dump($dt->minute);                                       // int(26)
var_dump($dt->second);                                       // int(11)
var_dump($dt->micro);                                        // int(123789)
var_dump($dt->dayOfWeek);                                    // int(3)
var_dump($dt->dayOfYear);                                    // int(248)
var_dump($dt->weekOfMonth);                                  // int(1)
var_dump($dt->weekOfYear);                                   // int(36)
var_dump($dt->daysInMonth);                                  // int(30)
var_dump($dt->timestamp);                                    // int(1346901971)
var_dump(Carbon::createFromDate(1975, 5, 21)->age);          // int(39) 


年月日时分秒
<?php

use Carbon\Carbon;

$dt = Carbon::now();

$dt->year = 1975;
$dt->month = 13;             // 年份會強制 +1,且月份變為 1 月
$dt->month = 5;
$dt->day = 21;
$dt->hour = 22;
$dt->minute = 32;
$dt->second = 5;
是否周一、周日、昨日、明日、生日等判断
<?php

use Carbon\Carbon;

$dt = Carbon::now();

$dt->isWeekday();
$dt->isWeekend();
$dt->isMonday(); $dt->isYesterday(); $dt->isToday(); $dt->isTomorrow(); $dt->isFuture(); $dt->isPast(); $dt->isLeapYear(); $dt->isSameDay(Carbon::now()); $born = Carbon::createFromDate(1987, 4, 23); $noCake = Carbon::createFromDate(2014, 9, 26); $yesCake = Carbon::createFromDate(2014, 4, 23); var_dump($born->isBirthday($noCake)); // bool(false) var_dump($born->isBirthday($yesCake)); // bool(true)



posted @ 2020-01-13 12:24  PHP急先锋  阅读(537)  评论(0编辑  收藏  举报