简体   繁体   English

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

[英]How can I set Zend DateTime Element to '0000-00-00 00:00:00'?

I am using the Zend Framework 2 DateTimeSelect. 我正在使用Zend Framework 2 DateTimeSelect。 How can I set the value (either in the form class or controller) to '0000-00-00 00:00:00'? 如何将值(在表单类或控制器中)设置为“ 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. 我想将此字段保留为空或为0,直到任务完成。

Many Thanks Matt 非常感谢Matt

You might have a misconception as to how years are counted arround the 1 bc and 1 ad mark. 您可能对1 BC和1广告标记周围的年数有误解。

The last day month and year of before christus is 30th of december 1 bc Right after that follows the 1st January 1 ad(Anno Domini). christus的最后一天和年份是公元前12月1日30日,紧随其后的1月1日广告(Anno Domini)。 Historically speaking there is no year 0 it start's with year one. 从历史上讲,没有0年始于1年。

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. 这意味着,如果我们创建DateTime对象并将日期设置为day = 0,month = 0,year = 0,则仍将位于christus日期之前的区域。

$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" } object(DateTime)#1(3){[“ date”] => string(20)“ -0001-11-30 00:00:00” [“ timezone_type”] => int(3)[“ timezone”] => string(13)“欧洲/柏林”}

-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. 现在,与setDate方法不同,构造函数将字符串作为参数解析为Time Object。 Which basically calls the set Date method at the end with the same 它基本上以相同的结尾调用set Date方法

day = 0 month = 0 year = 0 天= 0个月= 0年= 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" } object(DateTime)#1(3){[“ date”] => string(20)“ -0001-11-30 00:00:00” [“ timezone_type”] => int(3)[“ timezone”] => string(13)“欧洲/柏林”}

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. 这导致我得出这样的结论,即开箱即用的DateTime对象类来呈现特定的日期“ 0000-00-00:00:00:00”在文学上是不可能的,而且历史上是不正确的。

Could you please elaborate as to why you want to this in detail? 您能否详细说明为什么要这样做?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM