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?

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

报告相同问题?

悬赏问题

  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果