如果要想将英文文本日期时间解析为Unix时间戳,需要使用到php的strtotime()函数,下面简单介绍下其函数定义,语法参数释义,最后贴上部分示例代码
1、strtotime()函数定义
strtotime() 函数将任何英文文本的日期或时间描述解析为 Unix 时间戳(自 January 1 1970 00:00:00 GMT 起的秒数)。
2、strtotime()语法
strtotime(time,now);
参数含义:
- time 必需。规定日期/时间字符串。
- now 可选。规定用来计算返回值的时间戳。如果省略该参数,则使用当前时间。
3、strtotime()用法
$dates = "2020-07-01";
$starttime =strtotime($dates); //获取7月1号的时间戳
//获取7月月底的时间戳,+1 month 即 2020-08-01, -1 second,就是2020年7月31号23时59分59秒的时间
$endtime =strtotime("$dates +1 month -1 second");
Tip:还可使用 +1 week 3 days 7 hours、strtotime("next Monday")、strtotime("last Sunday")等形式
本文链接:https://www.23thi.com/25.html
除非特殊声明,本站文章均为原创,转载请务必保留本文链接