首页 > 解决方案 > 如何生成特定日期,例如 3 月 13 日

问题描述

我一直在使用以下代码来生成日期。

$datejoined = strip_tags(date('Y-m-d H:i:s', strtotime("+1 day")));

如何生成 4 月 13 日的具体日期?

标签: php

解决方案


strtotime()可以从几乎任何文本行生成日期日期。 strtotime('April 13')当年 4 月 13 日可以。使用以下代码行对其进行测试:

  print date('Y-m-d H:i:s', strtotime('April 13'));

但我个人建议您使用更快的功能mktime()

mktime(0, 0, 0, 4, 13); // 0:00:00, 4th month, 13 day, [current year].

推荐阅读