php中如何想时间转为时间戳,学习猿地-php如何把时间转为时间戳

在php中可以通过strtotime函数把时间转为时间戳,其语法是“strtotime(time,now);”,参数time表示日期时间字符串,而参数now是用来计算返回值的时间戳。

4c1ffa63fafd89169f57dd4a70252058.jpg

strtotime() 函数将任何英文文本的日期或时间描述解析为 Unix 时间戳(自 January 1 1970 00:00:00 GMT 起的秒数)。

注意:如果年份表示使用两位数格式,则值 0-69 会映射为 2000-2069,值 70-100 会映射为 1970-2000。

注意:请注意 m/d/y 或 d-m-y 格式的日期,如果分隔符是斜线(/),则使用美洲的 m/d/y 格式。如果分隔符是横杠(-)或者点(.),则使用欧洲的 d-m-y 格式。为了避免潜在的错误,您应该尽可能使用 YYYY-MM-DD 格式或者使用 date_create_from_format() 函数。

语法strtotime(time,now);

参数

time必需。规定日期/时间字符串。

now可选。规定用来计算返回值的时间戳。如果省略该参数,则使用当前时间。

实例:<?php

echo(strtotime("now") . "
");

echo(strtotime("5 September 2016") . "
");

echo(strtotime("+5 hours") . "
");

echo(strtotime("+1 week") . "
");

echo(strtotime("+1 week 3 days 7 hours 5 seconds") . "
");

echo(strtotime("next Monday") . "
");

echo(strtotime("last Sunday"));

?>

运行结果是:1604901378

1473004800

1604919378

1605506178

1605790583

1605456000

1604764800

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值