Created
August 31, 2015 13:02
-
-
Save sword-jin/0411d20802ec497c445e to your computer and use it in GitHub Desktop.
Carbon 的简单使用
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
echo Carbon::now()->addDays(4); //2015-09-04 20:39:45 | |
echo Carbon::now()->addWeeks(4); //2015-09-28 20:39:56 | |
echo Carbon::now()->subWeeks(4); //2015-09-28 20:39:56 | |
echo Carbon::now()->tomorrow(); //2015-09-01 00:00:00 | |
echo Carbon::now()->yesterday(); //2015-08-30 00:00:00 | |
$time = Carbon::now()->subYears(1)->timestamp; | |
echo $time; //1409488994 | |
$date = Carbon::createFromTimestamp($time); | |
echo $date; //2014-08-31 20:43:58 | |
echo $date->diffForHumans(); //1 year ago | |
$date = Carbon::now()->addDays(4)->addMinutes(25); | |
echo $date->diffForHumans(); //4 days from now | |
$date = Carbon::now(); | |
echo $date->startOfMonth(); //2015-08-01 00:00:00 | |
echo $date->endOfMonth(); //2015-08-31 23:59:59 | |
echo $date->toDateString(); //2015-08-31 | |
echo $date->toFormattedDateString(); //Aug 31, 2015 | |
echo $date->toATOMString(); // 2015-08-31T23:59:59+08:00 | |
echo new Carbon('next day'); //2015-09-01 20:53:18 | |
echo new Carbon('last Friday'); //2015-08-28 00:00:00 | |
echo new Carbon('this Saturday'); //2015-09-05 00:00:00 | |
$date = new Carbon('this Saturday'); | |
echo $date->dayOfWeek; //6 | |
echo $date->month; //9 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment