strtotime不能使用mm-dd-yyyy [英] strtotime not working with mm-dd-yyyy

查看:107
本文介绍了strtotime不能使用mm-dd-yyyy的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想将这些日期保存为时间戳,以便它们可以轻松被操纵/排序。 p>

当我尝试将mm-dd-yyyy类型的日期转换为时间戳时,它失败。



当脚本运行,它不知道它将被馈送什么格式,因此不能指定。所有其他格式的日期似乎都很好转换。



任何人都可以建议如何解决这个问题,或者替代方法是将所有日期格式转换为可订购,一致的格式可以被操纵?



非常感谢

解决方案

它以dd-mm-yyyy和 / 以mm / dd / yyyy形式显示 - 的字符串。 p>

另请参见问题对文档的评论



可能的解决方案/解决方法:




  • 在php 5.3上,使用 date_create_from_format

  • 在较旧的php而不是窗口,请使用 strptime

  • 可以使用,或者在必要时将 - 替换为 / ,或使用建议您可以找到的其中一个正则表达式链接的问题。



请注意,在某些时候,您需要知道要开始的格式。计算机不是心灵监视器。如果不提供区别,他们不能,也不能区分重叠范围(mm和dd <= 12)中的mm-dd-yyyy和dd-mm-yyyy。


I have a script which is fed dates in numerous different formats.

I want to save these dates as timestamps so they can easily be manipulated/ordered.

When i try an convert a mm-dd-yyyy type date to a timestamp, it fails.

When the script runs, it does not know what format it will be fed, and as such this cannot be specified. Near all other formats of date seem to be converted fine.

Could anyone advise how to fix this, or alternatively an alternative way that all date formats can be converted to an orderable, consistent format that can be manipulated?

Many Thanks

解决方案

It sees strings with - in them as dd-mm-yyyy and / as mm/dd/yyyy.

See also this question and the comments on the documentation.

Possible solutions / workarounds:

  • on php 5.3, use date_create_from_format
  • on older php and not on windows, use strptime
  • if neither can be used, either replace the - to / when necessary, or use one of the regexes suggested you can find through the linked question.

Note however that at some time you do need to know what the format is to start with. Computers are not mindreaders. They can't, and never will be able to, distinguish between mm-dd-yyyy and dd-mm-yyyy in the overlap ranges (both mm and dd <= 12) if you don't provide the distinction.

这篇关于strtotime不能使用mm-dd-yyyy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆