time()
时间戳 int(1524897548)
date(format,timestamp)
format 必需.指定时间戳格式
[plain] view plain copy
- <code class="language-php">Y:年
- m:月
- d:日
- H:小时 带首位0,24小时格式
- h:小时 带首位0,12小时格式
- i:分钟
- s:秒(00-59)
- a:午前-am;午后-pm</code>
timestamp 可选,规定时间戳.默认为当前时间
大小写区分很重要,如:
-
echo date("Y-m-d H:m:s") ;//H 2018-04-28 14:39:08 24小时制 -
echo date("Y-m-d h:m:s") ;//h 2018-04-28 02:39:08 12小时制
日期转时间戳 strtotime()
strtotime可以识别中文,英文,数字
[php] view plain copy
- <code class="language-php">echo date("Y-m-d H:m:s",strtotime("now")), "<br>";
- echo date("Y-m-d H:m:s",strtotime("10 September 2018")), "<br>";
- echo date("Y-m-d H:m:s",strtotime("+1 day")), "<br>";
- echo date("Y-m-d H:m:s",strtotime("+1 week")), "<br>";
- echo date("Y-m-d H:m:s",strtotime("+1 week 2 days 4 hours 2 seconds")), "<br>";
- echo date("Y-m-d H:m:s",strtotime("next Thursday")), "<br>";
- echo date("Y-m-d H:m:s",strtotime("last Monday")), "<br>";</code>
输出为
-
2018-04-28 14:04:11 -
2018-09-10 00:09:00 -
2018-04-29 14:04:11 -
2018-05-05 14:05:11 -
2018-05-07 18:05:13 -
2018-05-03 00:05:00 -
2018-04-23 00:04:00
1082

被折叠的 条评论
为什么被折叠?



