• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..20-May-2021-

bin/H20-May-2021-2719

src/Carbon/H20-May-2021-53,82525,272

LICENSEH A D24-Feb-20211 KiB2016

composer.jsonH A D24-Feb-20212.4 KiB9695

contributing.mdH A D24-Feb-20216.5 KiB155108

extension.neonH A D24-Feb-2021136 65

phpmd.xmlH A D24-Feb-20211.8 KiB4746

readme.mdH A D24-Feb-20216 KiB14093

readme.md

1# Carbon
2
3[![Latest Stable Version](https://img.shields.io/packagist/v/nesbot/carbon.svg?style=flat-square)](https://packagist.org/packages/nesbot/carbon)
4[![Total Downloads](https://img.shields.io/packagist/dt/nesbot/carbon.svg?style=flat-square)](https://packagist.org/packages/nesbot/carbon)
5[![GitHub Actions](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fbriannesbitt%2FCarbon%2Fbadge&style=flat-square&label=Build&logo=none)](https://actions-badge.atrox.dev/briannesbitt/Carbon/goto)
6[![StyleCI](https://github.styleci.io/repos/5724990/shield?style=flat-square)](https://github.styleci.io/repos/5724990)
7[![codecov.io](https://img.shields.io/codecov/c/github/briannesbitt/Carbon.svg?style=flat-square)](https://codecov.io/github/briannesbitt/Carbon?branch=master)
8[![PHPStan](https://img.shields.io/badge/PHPStan-enabled-44CC11.svg?longCache=true&style=flat-square)](https://github.com/phpstan/phpstan)
9[![Tidelift](https://tidelift.com/badges/github/briannesbitt/Carbon)](https://tidelift.com/subscription/pkg/packagist-nesbot-carbon?utm_source=packagist-nesbot-carbon&utm_medium=referral&utm_campaign=readme)
10
11An international PHP extension for DateTime. [http://carbon.nesbot.com](http://carbon.nesbot.com)
12
13```php
14<?php
15
16use Carbon\Carbon;
17
18printf("Right now is %s", Carbon::now()->toDateTimeString());
19printf("Right now in Vancouver is %s", Carbon::now('America/Vancouver'));  //implicit __toString()
20$tomorrow = Carbon::now()->addDay();
21$lastWeek = Carbon::now()->subWeek();
22$nextSummerOlympics = Carbon::createFromDate(2016)->addYears(4);
23
24$officialDate = Carbon::now()->toRfc2822String();
25
26$howOldAmI = Carbon::createFromDate(1975, 5, 21)->age;
27
28$noonTodayLondonTime = Carbon::createFromTime(12, 0, 0, 'Europe/London');
29
30$internetWillBlowUpOn = Carbon::create(2038, 01, 19, 3, 14, 7, 'GMT');
31
32// Don't really want this to happen so mock now
33Carbon::setTestNow(Carbon::createFromDate(2000, 1, 1));
34
35// comparisons are always done in UTC
36if (Carbon::now()->gte($internetWillBlowUpOn)) {
37    die();
38}
39
40// Phew! Return to normal behaviour
41Carbon::setTestNow();
42
43if (Carbon::now()->isWeekend()) {
44    echo 'Party!';
45}
46// Over 200 languages (and over 500 regional variants) supported:
47echo Carbon::now()->subMinutes(2)->diffForHumans(); // '2 minutes ago'
48echo Carbon::now()->subMinutes(2)->locale('zh_CN')->diffForHumans(); // '2分钟前'
49echo Carbon::parse('2019-07-23 14:51')->isoFormat('LLLL'); // 'Tuesday, July 23, 2019 2:51 PM'
50echo Carbon::parse('2019-07-23 14:51')->locale('fr_FR')->isoFormat('LLLL'); // 'mardi 23 juillet 2019 14:51'
51
52// ... but also does 'from now', 'after' and 'before'
53// rolling up to seconds, minutes, hours, days, months, years
54
55$daysSinceEpoch = Carbon::createFromTimestamp(0)->diffInDays();
56```
57
58[Get supported nesbot/carbon with the Tidelift Subscription](https://tidelift.com/subscription/pkg/packagist-nesbot-carbon?utm_source=packagist-nesbot-carbon&utm_medium=referral&utm_campaign=readme)
59
60## Installation
61
62### With Composer
63
64```
65$ composer require nesbot/carbon
66```
67
68```json
69{
70    "require": {
71        "nesbot/carbon": "^2.16"
72    }
73}
74```
75
76```php
77<?php
78require 'vendor/autoload.php';
79
80use Carbon\Carbon;
81
82printf("Now: %s", Carbon::now());
83```
84
85### Without Composer
86
87Why are you not using [composer](http://getcomposer.org/)? Download the Carbon [latest release](https://github.com/briannesbitt/Carbon/releases) and put the contents of the ZIP archive into a directory in your project. Then require the file `autoload.php` to get all classes and dependencies loaded on need.
88
89```php
90<?php
91require 'path-to-Carbon-directory/autoload.php';
92
93use Carbon\Carbon;
94
95printf("Now: %s", Carbon::now());
96```
97
98## Docs
99
100[http://carbon.nesbot.com/docs](http://carbon.nesbot.com/docs)
101
102## Security contact information
103
104To report a security vulnerability, please use the
105[Tidelift security contact](https://tidelift.com/security).
106Tidelift will coordinate the fix and disclosure.
107
108## Credits
109
110### Contributors
111
112This project exists thanks to all the people who contribute.
113
114<a href="https://github.com/briannesbitt/Carbon/graphs/contributors" target="_blank"><img src="https://opencollective.com/Carbon/contributors.svg?width=890&button=false" /></a>
115
116### Translators
117
118[Thanks to people helping us to translate Carbon in so many languages](https://carbon.nesbot.com/contribute/translators/)
119
120### Backers
121
122Thank you to all our backers! �� [[Become a backer](https://opencollective.com/Carbon#backer)]
123
124<a href="https://opencollective.com/Carbon#backers" target="_blank"><img src="https://opencollective.com/Carbon/backers.svg?width=890"></a>
125
126### Sponsors
127
128Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/Carbon#sponsor)]
129<a href="https://opencollective.com/Carbon/sponsor/0/website" target="_blank"><img src="https://opencollective.com/Carbon/sponsor/0/avatar.svg"></a>
130<a href="https://opencollective.com/Carbon/sponsor/1/website" target="_blank"><img src="https://opencollective.com/Carbon/sponsor/1/avatar.svg"></a>
131<a href="https://opencollective.com/Carbon/sponsor/2/website" target="_blank"><img src="https://opencollective.com/Carbon/sponsor/2/avatar.svg"></a>
132<a href="https://opencollective.com/Carbon/sponsor/3/website" target="_blank"><img src="https://opencollective.com/Carbon/sponsor/3/avatar.svg"></a>
133<a href="https://opencollective.com/Carbon/sponsor/4/website" target="_blank"><img src="https://opencollective.com/Carbon/sponsor/4/avatar.svg"></a>
134
135## Carbon for enterprise
136
137Available as part of the Tidelift Subscription.
138
139The maintainers of ``Carbon`` and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/packagist-nesbot-carbon?utm_source=packagist-nesbot-carbon&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
140