> **This file is autogenerated. Please see the [Contributing](#about-contributing) section from more information.**
# Carbon
[![Latest Stable Version](https://poser.pugx.org/nesbot/carbon/v/stable.png)](https://packagist.org/packages/nesbot/carbon) [![Total Downloads](https://poser.pugx.org/nesbot/carbon/downloads.png)](https://packagist.org/packages/nesbot/carbon) [![Build Status](https://secure.travis-ci.org/briannesbitt/Carbon.png)](http://travis-ci.org/briannesbitt/Carbon)
A simple API extension for DateTime with PHP 5.3+
```php
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();
```
## README Contents
* [Installation](#install)
* [Requirements](#requirements)
* [With composer](#install-composer)
* [Without composer](#install-nocomposer)
* [API](#api)
* [Instantiation](#api-instantiation)
* [Testing Aids](#api-testing)
* [Getters](#api-getters)
* [Setters](#api-setters)
* [Fluent Setters](#api-settersfluent)
* [IsSet](#api-isset)
* [String Formatting and Localization](#api-formatting)
* [Common Formats](#api-commonformats)
* [Comparison](#api-comparison)
* [Addition and Subtraction](#api-addsub)
* [Difference](#api-difference)
* [Difference for Humans](#api-humandiff)
* [Modifiers](#api-modifiers)
* [Constants](#api-constants)
* [About](#about)
* [Contributing](#about-contributing)
* [Author](#about-author)
* [License](#about-license)
* [History](#about-history)
* [Why the name Carbon?](#about-whyname)
<a name="install"/>
## Installation
<a name="requirements"/>
### Requirements
- Any flavour of PHP 5.3+ should do
- [optional] PHPUnit to execute the test suite
<a name="install-composer"/>
### With Composer
The easiest way to install Carbon is via [composer](http://getcomposer.org/). Create the following `composer.json` file and run the `php composer.phar install` command to install it.
```json
{
"require": {
"nesbot/Carbon": "*"
}
}
```
```php
<?php
require 'vendor/autoload.php';
use Carbon\Carbon;
printf("Now: %s", Carbon::now());
```
<a name="install-nocomposer"/>
### Without Composer
Why are you not using [composer](http://getcomposer.org/)? Download [Carbon.php](https://github.com/briannesbitt/Carbon/blob/master/src/Carbon/Carbon.php) from the repo and save the file into your project path somewhere.
```php
<?php
require 'path/to/Carbon.php';
use Carbon\Carbon;
printf("Now: %s", Carbon::now());
```
<a name="api"/>
## API
The Carbon class is [inherited](http://php.net/manual/en/keyword.extends.php) from the PHP [DateTime](http://www.php.net/manual/en/class.datetime.php) class.
```php
<?php
class Carbon extends \DateTime
{
// code here
}
```
Carbon has all of the functions inherited from the base DateTime class. This approach allows you to access the base functionality if you see anything missing in Carbon but is there in DateTime.
> **Note: I live in Ottawa, Ontario, Canada and if the timezone is not specified in the examples then the default of 'America/Toronto' is to be assumed. Typically Ottawa is -0500 but when daylight savings time is on we are -0400.**
Special care has been taken to ensure timezones are handled correctly, and where appropriate are based on the underlying DateTime implementation. For example all comparisons are done in UTC or in the timezone of the datetime being used.
```php
$dtToronto = Carbon::createFromDate(2012, 1, 1, 'America/Toronto');
$dtVancouver = Carbon::createFromDate(2012, 1, 1, 'America/Vancouver');
echo $dtVancouver->diffInHours($dtToronto); // 3
```
Also `is` comparisons are done in the timezone of the provided Carbon instance. For example my current timezone is -13 hours from Tokyo. So `Carbon::now('Asia/Tokyo')->isToday()` would only return false for any time past 1 PM my time. This doesn't make sense since `now()` in tokyo is always today in Tokyo. Thus the comparison to `now()` is done in the same timezone as the current instance.
<a name="api-instantiation"/>
### Instantiation
There are several different methods available to create a new instance of Carbon. First there is a constructor. It overrides the [parent constructor](http://www.php.net/manual/en/datetime.construct.php) and you are best to read about the first parameter from the PHP manual and understand the date/time string formats it accepts. You'll hopefully find yourself rarely using the constructor but rather relying on the explicit static methods for improved readability.
```php
$carbon = new Carbon(); // equivalent to Carbon::now()
$carbon = new Carbon('first day of January 2008', 'America/Vancouver');
echo get_class($carbon); // 'Carbon\Carbon'
```
You'll notice above that the timezone (2nd) parameter was passed as a string rather than a `\DateTimeZone` instance. All DateTimeZone parameters have been augmented so you can pass a DateTimeZone instance or a string and the timezone will be created for you. This is again shown in the next example which also introduces the `now()` function.
```php
$now = Carbon::now();
$nowInLondonTz = Carbon::now(new DateTimeZone('Europe/London'));
// or just pass the timezone as a string
$nowInLondonTz = Carbon::now('Europe/London');
```
If you really love your fluid method calls and get frustrated by the extra line or ugly pair of brackets necessary when using the constructor you'll enjoy the `parse` method.
```php
echo (new Carbon('first day of December 2008'))->addWeeks(2); // 2008-12-15 00:00:00
echo Carbon::parse('first day of December 2008')->addWeeks(2); // 2008-12-15 00:00:00
```
To accompany `now()`, a few other static instantiation helpers exist to create widely known instances. The only thing to really notice here is that `today()`, `tomorrow()` and `yesterday()`, besides behaving as expected, all accept a timezone parameter and each has their time value set to `00:00:00`.
```php
$now = Carbon::now();
echo $now; // 2014-09-24 23:55:55
$today = Carbon::today();
echo $today; // 2014-09-24 00:00:00
$tomorrow = Carbon::tomorrow('Europe/London');
echo $tomorrow; // 2014-09-26 00:00:00
$yesterday = Carbon::yesterday();
echo $yesterday; // 2014-09-23 00:00:00
```
The next group of static helpers are the `createXXX()` helpers. Most of the static `create` functions allow you to provide as many or as few arguments as you want and will provide default values for all others. Generally default values are the current date, time or timezone. Higher values will wrap appropriately but invalid values will throw an `InvalidArgumentException` with an informative message. The message is obtained from an [DateTime::getLastErrors()](http://php.net/manual/en/datetime.getlasterrors.php) call.
```php
Carbon::createFromDate($year, $month, $day, $tz);
Carbon::createFromTime($hour, $minute,
没有合适的资源?快使用搜索试试~ 我知道了~
pyramid:Laravel写的分销系统
共3629个文件
php:2792个
txt:96个
json:84个
1星 需积分: 17 5 下载量 86 浏览量
2021-03-11
17:34:10
上传
评论
收藏 9.41MB ZIP 举报
温馨提示
微信分销系统 适用于Laravel的微信分销系统
资源详情
资源评论
资源推荐
收起资源包目录
pyramid:Laravel写的分销系统 (3629个子文件)
a 0B
url_matcher1.apache 6KB
url_matcher2.apache 184B
APPS 269B
artisan 2KB
AUTHORS 219B
boris 300B
boris 25B
.bowerrc 53B
CHANGES 6KB
CHARSETS 968B
ItemController.class 0B
openssl.cnf 104B
code_coverage_id_rsa 2KB
ab.dat.copy 0B
abc.dat.copy 0B
a.dat.copy 0B
create-command-test 8KB
create-pear 7KB
create-phar 2KB
create-single-file 18KB
ca.crt 1KB
encrypt2.crt 1KB
sign.crt 1KB
encrypt.crt 1KB
style.css 117KB
materialize.min.css 116KB
bootstrap.min.css 107KB
font-awesome.min.css 21KB
faqi.css 12KB
debugbar.css 11KB
laravel-debugbar.css 10KB
whoops.base.css 7KB
css3.css 7KB
openhandler.css 6KB
widgets.css 6KB
css2.css 4KB
widget.css 3KB
widget.css 2KB
github.css 2KB
widget.css 287B
resources.csv 96B
valid.csv 36B
empty.csv 0B
resources.dat 352B
resources.dat 3B
bar.dat 0B
ab.dat 0B
abc.dat 0B
a.dat 0B
smoke.conf.php.default 2KB
acceptance.conf.php.default 1KB
phpunit.xml.dist 1KB
phpunit.xml.dist 1KB
phpunit.xml.dist 1KB
phpunit.xml.dist 981B
phpunit.xml.dist 916B
phpunit.xml.dist 915B
phpunit.xml.dist 912B
phpunit.xml.dist 912B
phpunit.xml.dist 911B
phpunit.xml.dist 910B
phpunit.xml.dist 908B
phpunit.xml.dist 861B
phpunit.xml.dist 860B
phpunit.xml.dist 857B
phpunit.xml.dist 856B
phpunit.xml.dist 855B
phpunit.xml.dist 812B
phpunit.xml.dist 809B
phpunit.xml.dist 698B
phpunit.xml.dist 692B
phpunit.xml.dist 643B
phpunit.xml.dist 554B
phpunit.xml.dist 483B
phpunit.xml.dist 390B
.editorconfig 193B
.empty 0B
fontawesome-webfont.eot 55KB
glyphicons-halflings-regular.eot 20KB
hiddeninput.exe 9KB
inlineHTMLandPHPtest.file-test 363B
onlyInlineHTML.file-test 124B
onlyPHP.file-test 114B
test.gif 35B
.gitattributes 73B
.gitattributes 42B
.gitattributes 12B
.gitattributes 12B
.gitignore 92B
.gitignore 92B
.gitignore 77B
.gitignore 72B
.gitignore 67B
.gitignore 56B
.gitignore 45B
.gitignore 34B
.gitignore 34B
.gitignore 34B
.gitignore 34B
共 3629 条
- 1
- 2
- 3
- 4
- 5
- 6
- 37
皮卡学长
- 粉丝: 76
- 资源: 4622
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- vue自定义指令( 复制、拖动、权限)
- json格式文件备份redis数据库 工具
- Multi-Agent-Flocking.zip
- 指标公式未来函数检测工具V1.2
- projectData
- SQL Server 性能监视器,它旨在提供开箱即用的全面监控,并作为您自己的项目或应用程序的监控框架 它在本地数据库中收集性能
- Python 程序语言设计模式思路-并发模式:线程池模式:管理线程池,优化线程创建和销毁
- 股事汇投资工具-实时新闻、财经日历、市场快讯、持仓查询、外汇兑换、换算工具、大盘云图、江恩工具、指标检测等
- webrtc-streamer
- html+css+'青春献礼二十大 红色旅游助乡村'为主题的网页设计 2022年参与学校网页设计比赛时完成的
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论1