为了以我想要的正确格式获取日期,我使用了
date("d-m-Y")
。现在我想在以下格式中除了日期外还获得时间 H:M:S
。我该如何进行?string date ( string $format [, int $timestamp = time() ] )
string
的含义。其次,第一个参数应该是一个包含格式的字符串。还有一个可选的第二个参数,用于传递您自己的时间戳(以从某个时间构造字符串,而不是现在)。date("d-m-Y") // produces something like 03-12-2012
d
代表月份中的日期(如果必要,则带前导零)。m
代表月份,同样如果必要,则带前导零。而Y
代表完整的四位数年份。所有这些都在上述链接中有记录。h 12-hour format of an hour with leading zeros 01 through 12
i Minutes with leading zeros 00 to 59
s Seconds, with leading zeros 00 through 59
date("d-m-Y h:i:s"); // produces something like 03-12-2012 03:29:13
您可以在同一日期函数调用中组合两者
date("d-m-Y H:i:s");
``` date(format1, format2) ```
date("d-m-Y H:i:s")
查看手册以获取更多信息:http://php.net/manual/zh/function.date.php
正如@ThomasVdBerge指出的那样,要显示分钟,您需要使用字符'i'