dongmo1708 2011-08-02 21:18
浏览 14
已采纳

用于将日期解析为零件的函数

Is there any nice function in PHP to parse the date into parts given the specified format?

e.g.

some_function('20112000', 'dmY') 
some_function('2000-11-20', 'Y-m-d')
some_function('2000 text 11-20', 'Y text m-d')

array('d'=>20, 'm'=>11, 'Y'=>2000) expected in all of the above cases,
(assuming formats compatible with date() function)

Update:

I use PHP 5.1.9
This is also possible using Zend_Date, but it uses different formats than date() (e.g. ddMMyyyy)

  • 写回答

3条回答 默认 最新

  • dpi74187 2011-08-02 21:21
    关注

    With PHP >= 5.3, the DateTime::createFromFormat() allows one to parse a date according to a specified format.

    After that, you get a DateTime object, and up to your to work with it in order to get the array you want.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器