strtotime()函数PHP时间格式转化

strtotime()函数:把日期转换成时间戳;

1,strtotime()时间转化

$datetime=strtotime(date());
date("Y-m-d H:i",$datetime) 

2,获得今天零点的时间戳

   第一步,先获取unix时间戳

$todaytime=strtotime("today")

第二步,再转化成可读日期
使用的时候一定要注意标点符号,英文输入下的双引号

date("Y-m-d H:i:s",$todaytime)

日期格式:"Y-m-d H:i:s"   H小时(大写为24小时),i分,s秒

"Y-m-d"只显示年月日;
如:
 $todaytime=strtotime("today");
 echo '今天开始时间:'.date("Y-m-d H:i:s",$todaytime);

输出结果:

今天开始时间:2021-11-05 00:00:00
获取今天23:59:59

 ① $nextdaytime=strtotime(date('Y-m-d',time()))+24*60*60-1;
 ② $nextdaytime=strtotime(date('Y-m-d 23:59:59',time()));

 

3,常用格式:strtotime()时间转化

        获取今天格式
        echo strtotime('Today');
        echo strtotime(date('Y-m-d'));
        获取明天凌晨的时间戳
        echo strtotime(date(
'Y-m-d',strtotime('+1 day')));
        其它格式:一看就懂的不再加详细解释:

        echo "一周后:".date("Y-m-d",strtotime("+1 week"));
        echo "一周零一天一小时一秒后:".date("Y-m-d G:H:s",strtotime("+1 week 1 days 1 hours 1 seconds"));
        echo "下个星期一:".date("Y-m-d",strtotime("next Monday"));
        echo "上个周一:".date("Y-m-d",strtotime("last Monday"));
        echo "一个月前:".date("Y-m-d",strtotime("last month"));
        echo "一个月后:".date("Y-m-d",strtotime("+1 month"));
        echo "一年后:".date("Y-m-d",strtotime("+1 year"));


在实践中不断的成长,把每一个经历都记录下来,给需要的人一点微薄的帮助,在代码历程上少走弯路。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值