### Basic Carbon Usage with Composer Source: https://github.com/briannesbitt/carbon/blob/master/readme.md Include the Composer autoloader and use the Carbon class to get the current date and time. This example assumes Composer installation. ```php toDateTimeString()); printf("Right now in Vancouver is %s", Carbon::now('America/Vancouver')); //implicit __toString() $tomorrow = Carbon::now()->addDay(); $lastWeek = Carbon::now()->subWeek(); $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(); // something such as: // 19817.6771 $daysUntilInternetBlowUp = $internetWillBlowUpOn->diffInDays(); // Negative value since it's in the future: // -5037.4560 // Without parameter, difference is calculated from now, but doing $a->diff($b) // it will count time from $a to $b. Carbon::createFromTimestamp(0)->diffInDays($internetWillBlowUpOn); // 24855.1348 ``` -------------------------------- ### Update Dependencies Source: https://github.com/briannesbitt/carbon/blob/master/contributing.md Update project dependencies using Composer. Use the local phar or the globally installed composer. ```shell ./composer.phar update ``` ```shell composer update ``` -------------------------------- ### Run Unit Tests Source: https://github.com/briannesbitt/carbon/blob/master/contributing.md Execute the project's unit tests using PHPUnit to ensure code quality and stability. ```shell ./vendor/bin/phpunit ``` -------------------------------- ### Basic Carbon Usage without Composer Source: https://github.com/briannesbitt/carbon/blob/master/readme.md Manually include the Carbon autoloader after downloading the library. This method is suitable if Composer is not used. ```php /carbon.git cd Carbon git remote add upstream https://github.com/CarbonPHP/carbon.git ``` -------------------------------- ### Sync Local Repository with Upstream Source: https://github.com/briannesbitt/carbon/blob/master/contributing.md Fetch changes from the upstream remote and rebase your local branch to keep it up-to-date. ```shell git fetch origin git rebase origin/master ``` -------------------------------- ### Configure Git User Information Source: https://github.com/briannesbitt/carbon/blob/master/contributing.md Set your global Git user name and email. Remove the --global flag to set it only for the current repository. ```shell git config --global user.name "Your Name" git config --global user.email "your.email.address@example.com" ``` -------------------------------- ### Commit Changes Source: https://github.com/briannesbitt/carbon/blob/master/contributing.md Stage all changes and commit them with a descriptive message. For bug fixes, reference the issue number. ```shell git add --all git commit -m "The commit message log" ``` ```shell git commit -m "#21 Fix this or that" ``` -------------------------------- ### Create a New Feature Branch Source: https://github.com/briannesbitt/carbon/blob/master/contributing.md Create a new branch for your development work, based on the master branch. ```shell git checkout -b my-feature-branch -t origin/master ``` -------------------------------- ### Composer package.json configuration Source: https://github.com/briannesbitt/carbon/blob/master/readme.md Specify the Carbon version in your Composer JSON file. Ensure you are using a compatible version, such as '^3'. ```json { "require": { "nesbot/carbon": "^3" } } ``` -------------------------------- ### Push Changes to Fork Source: https://github.com/briannesbitt/carbon/blob/master/contributing.md Push your local feature branch to your remote GitHub fork to prepare for a pull request. ```shell git push origin my-feature-branch ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.