duanbiao4035 2017-04-19 17:54
浏览 90

PHP DateTime :: createFromFormat()的多种格式

Let's say the user can submit their time as strings in one of multiple formats. Is there any way in DateTime::createFromFormat() to specify multiple formats to parse.

Right now I notice if you specify a format, any missing elements cause an error.

For example, lets say I'm accepting both 1h22m34s and a 21m22s as valid time strings (the second implies 00h, but doesn't require it).

The following will throw an error on the second string when seen:

   $mytime = `21m22s`;
   echo DateTime::createFromFormat('H\hi\ms\s',$mytime)->format('H:i:s');

How can I work to allow it to parse multiple formats?

Or is there another, non-hack way to work with multiple formats?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

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