PHP code example of newteng / format-date
1. Go to this page and download the library: Download newteng/format-date library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
newteng / format-date example snippets
t = new \Newteng\FormatDate\FormatDateToStr();
echo $format->transform(date('Y-m-d H:i:s', time() - 1500)); // 25 分钟前
...
namespace App\Http\Controllers;
use Carbon\Carbon;
use Newteng\FormatDate\FormatDateToStr;
class IndexController extends Controller
{
public function index(FormatDateToStr $formatDateToStr)
{
$dateStr = date('Y-m-d H:i:s', time() - 1500);
// return $formatDateToStr->transform($dateStr);
// or
return app('format_date_to_str')->transform(Carbon::now()->subMinute(15)); // 15 分钟前
}
}