「Php/laravel/laravel5/日付」の版間の差分
提供: 初心者エンジニアの簡易メモ
(ページの作成:「==carbonを使う== use Carbon\Carbon; $current = Carbon::now(); // get today - 2015-12-19 00:00:00 $today = Carbon::today(); // get yesterday - 2015-12-18 00:00:00...」) |
(→carbonを使う) |
||
行1: | 行1: | ||
==carbonを使う== | ==carbonを使う== | ||
use Carbon\Carbon; | use Carbon\Carbon; | ||
+ | |||
+ | ==使い方== | ||
$current = Carbon::now(); | $current = Carbon::now(); | ||
// get today - 2015-12-19 00:00:00 | // get today - 2015-12-19 00:00:00 | ||
行11: | 行13: | ||
Carbon::createFromTime($hour, $minute, $second, $tz); | Carbon::createFromTime($hour, $minute, $second, $tz); | ||
Carbon::create($year, $month, $day, $hour, $minute, $second, $tz); | Carbon::create($year, $month, $day, $hour, $minute, $second, $tz); | ||
− | |||
$dt = Carbon::now(); | $dt = Carbon::now(); | ||
行20: | 行21: | ||
$dt->minute = 32; | $dt->minute = 32; | ||
$dt->second = 5; | $dt->second = 5; | ||
− | |||
echo $dt->toDateString(); // 2015-12-19 | echo $dt->toDateString(); // 2015-12-19 |
2016年8月10日 (水) 06:16時点における版
carbonを使う
use Carbon\Carbon;
使い方
$current = Carbon::now(); // get today - 2015-12-19 00:00:00 $today = Carbon::today(); // get yesterday - 2015-12-18 00:00:00 $yesterday = Carbon::yesterday(); // get tomorrow - 2015-12-20 00:00:00 $tomorrow = Carbon::tomorrow(); Carbon::createFromDate($year, $month, $day, $tz); Carbon::createFromTime($hour, $minute, $second, $tz); Carbon::create($year, $month, $day, $hour, $minute, $second, $tz);
$dt = Carbon::now(); $dt->year = 2015; $dt->month = 04; $dt->day = 21; $dt->hour = 22; $dt->minute = 32; $dt->second = 5;
echo $dt->toDateString(); // 2015-12-19 echo $dt->toTimeString(); // 10:10:16 echo $dt->toDateTimeString(); // 2015-12-19 10:10:16
参考:https://scotch.io/tutorials/easier-datetime-in-laravel-and-php-with-carbon