douqiang5933 2014-11-21 22:41
浏览 64
已采纳

如何将Zend DateTime元素设置为'0000-00-00 00:00:00'?

I am using the Zend Framework 2 DateTimeSelect. How can I set the value (either in the form class or controller) to '0000-00-00 00:00:00'? Currently it defaults to the end of the year. I get the following results when i try the following in the controller...

$date = date("0-0-0 0:0:0"); `This gives me the date as November 30th`
$date =  '0000-00-00 00:00:00';`This gives me the date as November 30th`
$date =  NULL; `This gives me the current date time.` 

 $form->get('datetime')->setValue($date);

I would like to leave this field either empty or as 0 until the task is complete.

Many Thanks Matt

  • 写回答

1条回答 默认 最新

  • dongzhenge2014 2014-11-25 12:56
    关注

    You might have a misconception as to how years are counted arround the 1 b.c and 1 a.d mark.

    The last day month and year of before christus is 30th of december 1 b.c. Right after that follows the 1st January 1 a.d(Anno Domini). Historically speaking there is no year 0 it start's with year one.

    Which means if we create DateTime Object and set a date to day=0, month=0, year=0 will still be in the before christus date region.

    $test = new DateTime();
    $test->setDate(0, 0, 0);
    //I left out timezone settings so it'll take the default timezone
    var_dump($test); exit;
    

    would outup:

    object(DateTime)#1 (3) { ["date"]=> string(20) "-0001-11-30 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Berlin" }

    -0001-11-30 looks a bit weird since php counts months beginning with 0 = January, .... , 11 = December.
    

    Now unlike the setDate method the constructor takes strings as a parameter which gets parsed into the Time Object. Which basically calls the set Date method at the end with the same

    day = 0 month = 0 year = 0

    which again would output:

    object(DateTime)#1 (3) { ["date"]=> string(20) "-0001-11-30 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Berlin" }

    This leads me to the conclusion that getting the out of the box DateTime Object Class to render the specific date "0000-00-00:00:00:00" is literary impossible and historically incorrect.

    Could you please elaborate as to why you want to this in detail?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能