現在の位置: ホーム> 最新記事一覧> 日付()関数を使用して、PHPの現在の日付と時刻を取得してフォーマットする方法は?

日付()関数を使用して、PHPの現在の日付と時刻を取得してフォーマットする方法は?

gitbox 2025-08-29

<?php エコー

PHPの現在の日付と時刻を取得してフォーマットするために日付()関数を使用する方法?

エコー "

In PHP, a function is a common way to get and format date and time. It can return the current server time or the date and time string of the specified time based on the format string you specify.

"
;エコー

基本的な構文:

;エコー "
string date(string \ $ format [、int \ $ timestamp = time())
"
; echo "
  • \$format : Required, defines the format of date/time.
  • \$timestamp : Optional, specify the timestamp, and the current time is used by default.
"
;
エコー

一般的なフォーマット文字:

; echo "
  • Y - four-digit year, such as 2025
  • m - two-digit month, such as 08
  • d - two-digit date, such as 27
  • H - 24-hour hours, such as 14
  • i - minutes, such as 05
  • s - seconds, such as 09
  • l - full name of the week, such as Wednesday
"
;
エコー

現在の日付と時刻の例を取得してください:

;エコー
<?php
エコー日付( &#39;ymd h:i:s&#39;); //出力は2025-08-27 14:05:09に似ています
?>
"
;
エコー "

フォーマット例:

"
;エコー
<?php
//完全にな日付と週のエコー日付を急行( &#39;l、d f y&#39;); // 2025年8月27日水曜日と同様の出力
?>
"
;
エコー "

By combining different format characters, you can customize the output form, such as displaying only dates, displaying only times, or including day of the week. The date() function is the basic tool for processing time in PHP development, which is very suitable for applications such as logging, time display and timing tasks.

"
;エコー "

まとめ:

"
;エコー "

Using the date() function, you can easily get the current date and time and customize the output by formatting the string. Remember to use a specific time zone, you can set date_default_timezone_set() before using date().

"
; ?> <?php //最後にコンテンツはありません エコー