dpxpz37157 2010-05-24 15:57
浏览 24
已采纳

PHP / Zend自定义日期输入格式

I'm creating a library component for other developers on my team using PHP and Zend. This component needs to be able to take as input a date (string) and another string telling it the format of that date. Looking through the Zend documentation and examples, I thought I found the solution -

$dateObject = Zend_Date('13.04.2006', array('date_format' => 'dd.MM.yyyy'));

this line, however, throws an error - call to undefined function.

So instead I tried this -

$dt = Zend_Locale_Format::getDate('13.04.2006', array('date_format' => 'dd.MM.yyyy'));

This gets the job done, but throws an error if a date that is entered isn't valid. The docs make it look like you can use the isDate() function to check validity -

Zend_Date::isDate('13.04.2006', array('date_format' => 'dd.MM.yyyy'))

but this line always returns false.

So my questions -

Am I going about this the right way? If not, is there a better way to handle this via Zend or straight PHP?

If I do use Zend_Locale_Format::getDate(), do I need to worry about a locale being set elsewhere and changing the results of the call?

I'm locked into PHP 5.2.6 on windows, btw... so 5.3+ functions & strptime() are out.

  • 写回答

3条回答 默认 最新

  • dougang1965 2010-05-24 16:37
    关注

    Take a look at this post. Maybe it will help.

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

报告相同问题?

悬赏问题

  • ¥15 聚类分析或者python进行数据分析
  • ¥15 如何用visual studio code实现html页面
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?