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

..03-May-2022-

bin/H03-May-2022-2920

src/Carbon/H03-May-2022-54,99825,559

LICENSEH A D03-Dec-20211 KiB2016

composer.jsonH A D03-Dec-20212.5 KiB10099

extension.neonH A D03-Dec-2021136 65

readme.mdH A D03-Dec-20216.2 KiB14595

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[![codecov.io](https://img.shields.io/codecov/c/github/briannesbitt/Carbon.svg?style=flat-square)](https://codecov.io/github/briannesbitt/Carbon?branch=master)
7[![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)
8
9An international PHP extension for DateTime. [https://carbon.nesbot.com](https://carbon.nesbot.com)
10
11```php
12<?php
13
14use Carbon\Carbon;
15
16printf("Right now is %s", Carbon::now()->toDateTimeString());
17printf("Right now in Vancouver is %s", Carbon::now('America/Vancouver'));  //implicit __toString()
18$tomorrow = Carbon::now()->addDay();
19$lastWeek = Carbon::now()->subWeek();
20$nextSummerOlympics = Carbon::createFromDate(2016)->addYears(4);
21
22$officialDate = Carbon::now()->toRfc2822String();
23
24$howOldAmI = Carbon::createFromDate(1975, 5, 21)->age;
25
26$noonTodayLondonTime = Carbon::createFromTime(12, 0, 0, 'Europe/London');
27
28$internetWillBlowUpOn = Carbon::create(2038, 01, 19, 3, 14, 7, 'GMT');
29
30// Don't really want this to happen so mock now
31Carbon::setTestNow(Carbon::createFromDate(2000, 1, 1));
32
33// comparisons are always done in UTC
34if (Carbon::now()->gte($internetWillBlowUpOn)) {
35    die();
36}
37
38// Phew! Return to normal behaviour
39Carbon::setTestNow();
40
41if (Carbon::now()->isWeekend()) {
42    echo 'Party!';
43}
44// Over 200 languages (and over 500 regional variants) supported:
45echo Carbon::now()->subMinutes(2)->diffForHumans(); // '2 minutes ago'
46echo Carbon::now()->subMinutes(2)->locale('zh_CN')->diffForHumans(); // '2分钟前'
47echo Carbon::parse('2019-07-23 14:51')->isoFormat('LLLL'); // 'Tuesday, July 23, 2019 2:51 PM'
48echo Carbon::parse('2019-07-23 14:51')->locale('fr_FR')->isoFormat('LLLL'); // 'mardi 23 juillet 2019 14:51'
49
50// ... but also does 'from now', 'after' and 'before'
51// rolling up to seconds, minutes, hours, days, months, years
52
53$daysSinceEpoch = Carbon::createFromTimestamp(0)->diffInDays();
54```
55
56[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)
57
58## Installation
59
60### With Composer
61
62```
63$ composer require nesbot/carbon
64```
65
66```json
67{
68    "require": {
69        "nesbot/carbon": "^2.16"
70    }
71}
72```
73
74```php
75<?php
76require 'vendor/autoload.php';
77
78use Carbon\Carbon;
79
80printf("Now: %s", Carbon::now());
81```
82
83### Without Composer
84
85Why are you not using [composer](https://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.
86
87```php
88<?php
89require 'path-to-Carbon-directory/autoload.php';
90
91use Carbon\Carbon;
92
93printf("Now: %s", Carbon::now());
94```
95
96## Docs
97
98[https://carbon.nesbot.com/docs](https://carbon.nesbot.com/docs)
99
100## Security contact information
101
102To report a security vulnerability, please use the
103[Tidelift security contact](https://tidelift.com/security).
104Tidelift will coordinate the fix and disclosure.
105
106## Credits
107
108### Contributors
109
110This project exists thanks to all the people who contribute.
111
112<a href="https://github.com/briannesbitt/Carbon/graphs/contributors" target="_blank"><img src="https://opencollective.com/Carbon/contributors.svg?width=890&button=false" /></a>
113
114### Translators
115
116[Thanks to people helping us to translate Carbon in so many languages](https://carbon.nesbot.com/contribute/translators/)
117
118### Sponsors
119
120Support this project by becoming a sponsor. Your logo will show up here with a link to your website.
121
122<a href="https://tidelift.com/subscription/pkg/packagist-nesbot-carbon?utm_source=packagist-nesbot-carbon&utm_medium=referral&utm_campaign=readme" target="_blank"><img src="https://carbon.nesbot.com/tidelift-brand.png" width="256" height="64"></a>
123<a href="https://onlinecasinohex.ca/?utm_source=opencollective&amp;utm_medium=github&amp;utm_campaign=Carbon" target="_blank"><img src="https://images.opencollective.com/hexcasinoca/2da3af2/logo/256.png" width="85" height="64"></a>
124<a href="https://opencollective.com/Carbon/sponsor/0/website" target="_blank"><img src="https://opencollective.com/Carbon/sponsor/0/avatar.svg"></a>
125<a href="https://opencollective.com/Carbon/sponsor/1/website" target="_blank"><img src="https://opencollective.com/Carbon/sponsor/1/avatar.svg"></a>
126<a href="https://opencollective.com/Carbon/sponsor/2/website" target="_blank"><img src="https://opencollective.com/Carbon/sponsor/2/avatar.svg"></a>
127<a href="https://opencollective.com/Carbon/sponsor/3/website" target="_blank"><img src="https://opencollective.com/Carbon/sponsor/3/avatar.svg"></a>
128<a href="https://opencollective.com/Carbon/sponsor/4/website" target="_blank"><img src="https://opencollective.com/Carbon/sponsor/4/avatar.svg"></a>
129
130[[Become a sponsor](https://opencollective.com/Carbon#sponsor)]
131
132### Backers
133
134Thank you to all our backers! ��
135
136<a href="https://opencollective.com/Carbon#backers" target="_blank"><img src="https://opencollective.com/Carbon/backers.svg?width=890"></a>
137
138[[Become a backer](https://opencollective.com/Carbon#backer)]
139
140## Carbon for enterprise
141
142Available as part of the Tidelift Subscription.
143
144The 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)
145