Skip to content
A simple PHP API extension for DateTime.
PHP
Branch: master
Clone or download
Latest commit 380e7da Sep 13, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Update FUNDING.yml Jun 25, 2019
bin Use require everywhere instead of include Aug 19, 2019
src/Carbon Fix #1886 Support slashes in hasFormat() Sep 13, 2019
tests #1886 Add hasFormat() tests Sep 13, 2019
.codecov.yml Mute codecov comments Jun 26, 2016
.editorconfig Ensure composer.json use 4 spaces Jul 21, 2016
.gitattributes Fix export ignore Aug 8, 2018
.gitignore Add language data from svenfuchs/rails-i18n Feb 25, 2019
.multi-tester.yml Unit tests improvements (#1588) Feb 12, 2019
.php_cs.dist Fix typo Aug 4, 2019
.styleci.yml First cleanup for version 2 May 23, 2018
.travis.yml Allow PHP 8 tests to fail until new PHP build is released Aug 12, 2019
LICENSE CS fixes Jul 9, 2014
build.php
composer.json Nit: Grammar (#1880) Sep 5, 2019
contributing.md Talk about "good first issue" label May 30, 2019
phpdoc.php #1857 Fix static methods typing autocompletion Aug 30, 2019
phpmd.xml Simplify context calculation Jul 19, 2019
phpstan.neon Allow static methods in mixin traits Aug 3, 2019
phpunit.xml.dist Allow to get context from macros using self::this() Sep 5, 2019
readme.md Restore badge URL Mar 31, 2019

readme.md

Carbon

Latest Stable Version Total Downloads Build Status StyleCI codecov.io PHPStan Tidelift

An international PHP extension for DateTime. http://carbon.nesbot.com

use Carbon\Carbon;

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(2016)->addYears(4);

$officialDate = Carbon::now()->toRfc2822String();

$howOldAmI = Carbon::createFromDate(1975, 5, 21)->age;

$noonTodayLondonTime = Carbon::createFromTime(12, 0, 0, 'Europe/London');

$internetWillBlowUpOn = Carbon::create(2038, 01, 19, 3, 14, 7, 'GMT');

// Don't really want this to happen so mock now
Carbon::setTestNow(Carbon::createFromDate(2000, 1, 1));

// comparisons are always done in UTC
if (Carbon::now()->gte($internetWillBlowUpOn)) {
    die();
}

// Phew! Return to normal behaviour
Carbon::setTestNow();

if (Carbon::now()->isWeekend()) {
    echo 'Party!';
}
// Over 200 languages (and over 500 regional variants) supported:
echo Carbon::now()->subMinutes(2)->diffForHumans(); // '2 minutes ago'
echo Carbon::now()->subMinutes(2)->locale('zh_CN')->diffForHumans(); // '2分钟前'
echo Carbon::parse('2019-07-23 14:51')->isoFormat('LLLL'); // 'Tuesday, July 23, 2019 2:51 PM'
echo Carbon::parse('2019-07-23 14:51')->locale('fr_FR')->isoFormat('LLLL'); // 'mardi 23 juillet 2019 14:51'

// ... but also does 'from now', 'after' and 'before'
// rolling up to seconds, minutes, hours, days, months, years

$daysSinceEpoch = Carbon::createFromTimestamp(0)->diffInDays();

Get supported nesbot/carbon with the Tidelift Subscription

Installation

With Composer

$ composer require nesbot/carbon
{
    "require": {
        "nesbot/carbon": "^2.16"
    }
}
<?php
require 'vendor/autoload.php';

use Carbon\Carbon;

printf("Now: %s", Carbon::now());

Without Composer

Why are you not using composer? Download the Carbon latest release 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.

<?php
require 'path-to-Carbon-directory/autoload.php';

use Carbon\Carbon;

printf("Now: %s", Carbon::now());

Docs

http://carbon.nesbot.com/docs

Security contact information

To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.

Credits

Contributors

This project exists thanks to all the people who contribute.

Translators

Thanks to people helping us to translate Carbon in so many languages

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

You can’t perform that action at this time.