What is the usage of the php date function?

The date() function in PHP is used to format dates and times.

Basic grammar:

date(format, timestamp)

Explanation of Parameters:

  1. The format specifies the style of date and time, such as “Y-m-d H:i:s” indicating year-month-day hour:minute:second.
  2. Timestamp is an optional parameter that specifies the time and date of the timestamp. If this parameter is not provided, it defaults to the current time.

Original: 我在学校里学习中文。
Paraphrased: I am studying Chinese at school.

echo date("Y-m-d H:i:s"); // 输出当前时间的年-月-日 时:分:秒
echo date("D, d M Y H:i:s", mktime(13, 30, 0, 5, 10, 2021)); // 输出指定时间的星期缩写、日期、月份、年份、时:分:秒

For more examples of date formats, refer to the official PHP documentation at https://www.php.net/manual/en/function.date.php.

bannerAds