Convert timezones and formats with Carbon wrapped in a PHP7 command line symfony console application.
First make sure you have at least PHP 7 installed. Then, there are multiple ways to install. Choose the one best for you:
The most preferred method of installation is to use phive. This avoids dependency conflicts between tools using different versions of libraries (like Carbon or Symfony Console).
Install to some directory that's in your
PATH such as
phive install carbon --target ~/bin
phive.xml in your current directory.
If you're into versioning your dotfiles, consider creating a symlink to this.
Then you'll be able to easily update when new versions are released.
Download the latest phar release, set it executable,
and move it to a good
Here's a oneline
sudo command to make it available system-wide:
curl -sSL https://github.com/jpuck/carbon-console/releases/latest | egrep -o '/jpuck/carbon-console/releases/download/[0-9\.]*/carbon-console.phar"' | head -c-2 | wget --base=https://github.com/ -i - -O carbon && chmod +x carbon && sudo mv carbon /usr/local/bin/
If you don't have
sudo privileges, then you can omit the last part
sudo mv carbon /usr/local/bin/ and just save it somewhere in your user's
~/bin or simply execute it verbosely with the PHP CLI.
composer global require jpuck/carbon-console
Make sure your
PATH contains the global bin directory which you can find:
composer global config bin-dir --absolute
You can then add that location to your shell profile or rc so that it's always available. For example, if you're running Ubuntu 16.04 with bash, then this might work:
echo 'export PATH="$PATH:$HOME/.config/composer/vendor/bin"' >> ~/.bashrc
NOTE that you will probably have to contend with a dependency conflict sooner or later with each additional package you install. This is why phive is preferred.
git clone https://github.com/jpuck/carbon-console.git cd carbon-console composer install ./bin/carbon
After installing, run the
list command to see a list of commands:
help command to get help with any command's usage:
carbon help convert
The primary command is
convert which defaults input time now and output timezone local.
Usage: convert [-o|--timezone-out [TIMEZONE-OUT]] [-f|--format-out [FORMAT-OUT]] [--] [<time-in>]...
For the following examples, my system's local timezone is set to UTC.
When it's 8:00AM in Chicago, what time will it be here?
carbon convert 8:00AM America/Chicago
It's 5:18PM here, so what time is it in Casey Station?
carbon convert -o Antarctica/Casey
When it's 6:00PM here, what time will it be in Casey Station?
carbon convert 6:00PM -o Antarctica/Casey
When it's 6:00PM in Chicago, what time will it be in Casey Station?
carbon convert 6:00PM America/Chicago -o Antarctica/Casey
Let's format that output as 12-hour:minute
carbon convert 6:00PM America/Chicago -o Antarctica/Casey -f h:iA
If you use spaces in your format, make sure to quote the argument.
carbon convert 6:00PM America/Chicago -o Antarctica/Casey -f 'h:iA l, F j'
11:00AM Friday, February 17