php规定时间后失效,PHP strtotime转换在某些日期时间不起作用

我正在尝试从Web服务结果集中对我的datetime条目执行strtotime(绝不为null).

在循环和cnoverting时,我发现许多都无法使用strtotime进行转换.问题是什么?有效的格式与无效的格式之间没有区别.

1431109502 - 08-05-2015 13:25:02

- 06-15-2015 12:05:32 -- Didn't work (any that start with - didn't convert)

- 06-25-2015 11:30:30

- 06-15-2015 10:58:56

- 06-27-2015 20:33:31

- 06-28-2015 00:13:37

1431054141 - 07-05-2015 22:02:21

- 07-17-2015 07:23:57

- 07-22-2015 02:30:24

1431090998 - 08-05-2015 08:16:38

1433774646 - 08-06-2015 09:44:06

编辑:这是我用来尝试获得100%转化的一些代码.

$t = date_create_from_Format( 'd-m-Y H:i:s', trim($arrCurrentAlarms[$i]["DateTime"]) );

$sqldt = $t->format('Y-m-d H:i:s');

提供给我的输入始终采用以下格式:06-25-2015 11:30:30

(年月日hr min sec)

解决方法:

那是因为strtotime猜错了您的日期:

date('r', strtotime('08-05-2015 13:25:02')) -> Fri, 08 May 2015 13:25:02 -0500

date('r', strtotime('06-25-2015 11:30:30')) -> Wed, 31 Dec 1969 18:00:00 -0600

现在注意第一个值是5月8日:strtotime正在考虑您的日期为dd-mm-yyyy,而您确实有mm-dd-yyyy.

请注意第二个日期如何显示为1969年12月-这就是整数0(又称布尔FALSE)作为我特定时区中的日期如何显示的方式.因为失败,所以日历中没有月份25.

由于猜测错误,因此您必须改用date_create_from_format(),然后告诉php您的日期采用的格式.

标签:strtotime,datetime,php

来源: https://codeday.me/bug/20191119/2039774.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值