PHPとJavaScriptで、日付を扱う
日付を様々な形式で扱います。
・PHP
$datetime = new DateTimeImmutable(); $today = $datetime->format('Y年m月d日'); // 2021年09月10日 $today = $datetime->format('Y/m/d日'); // 2021/09/10 $next_monday = $datetime->modify('next monday')->format('Y年m月d日'); // 2021年09月13日 $yesterday = $datetime->modify('-1 day')->format('Y年m月d日'); // 2021年09月09日 $xday_datetime = new DateTimeImmutable('2021-12-25'); $xday = xday_datetime->format('Y年m月d日'); // 2021年12月25日 $youbi = xday_datetime->format('w'); // 土
var date = new Date(); var year = date.getFullYear(); // 2021 var month = date.getMonth() + 1; // 9 var day = date.getDate(); // 10 var today = year + '年' + month + '月' + day + '日'; // 2021年09月10日 var date = new Date('2021-12-25'); var year = date.getFullYear(); // 2021 var month = date.getMonth() + 1; // 12 var day = date.getDate(); // 25