Easier date and time handling with Carbon
Laravel bundles Carbon (https://github.com/briannesbitt/Carbon), which extends and augments PHP's native DateTime
object with more expressive methods. Laravel uses it mainly to provide more expressive methods on the date and time properties (created_at
, updated_at
, and deleted_at
) of an Eloquent object. However, since the library is already there, it would be a shame not to use it elsewhere in the code of your application.
Instantiating Carbon objects
Carbon objects are meant to be instantiated like normal DateTime
objects. They do, however, support a handful of more expressive methods:
- Carbon objects can be instantiated using the default constructor that will use the current date and time as follows:
$now = new Carbon();
- They can be instantiated using the current date and time in a given timezone as follows:
$jetzt = new Carbon('Europe/Berlin');
- They can be instantiated using expressive methods as follows:
$yesterday = Carbon::yesterday...