Skip to content

Instantly share code, notes, and snippets.

@atrakeur
Last active June 6, 2016 00:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atrakeur/9768077 to your computer and use it in GitHub Desktop.
Save atrakeur/9768077 to your computer and use it in GitHub Desktop.
<?php
/*
* Defaut display of Carbon dates can be changed using the method
* This method have to be called BEFORE outputing any date to string
*/
\Carbon\Carbon::setToStringFormat('d-m-Y H:i:s');
/*
* Can be setup in your models constructors like this:
*/
public function __construct() {
//Call the parent constructor
parent::__construct();
//Set the format used by Carbon when converting date to string
\Carbon\Carbon::setToStringFormat('d-m-Y H:i:s');
//all dates like 2014-03-25 17:37:54 look like 25-03-2014 17:37:54 now
}
/*
* Or in the start.php file like that:
*/
/*
|--------------------------------------------------------------------------
| Change the default date format
|--------------------------------------------------------------------------
|
| Change date format output to french format
|
*/
\Carbon\Carbon::setToStringFormat('d-m-Y H:i:s');
/*
* It can even be set inside your filters.php (to conditionnaly format date based on url for example)
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment