[英]Adapt datetime field in Yii automatically to right format
I'd like to have a field inside a form, which has a format like dd.MM.yyyy HH:mm. 我想在表单中有一个字段,其格式类似于dd.MM.yyyy HH:mm。 I've done this with the date validator.
我用日期验证器完成了这个。 But now I have the problem, that the user always have to enter a time, not only the specified day.
但现在我遇到了问题,用户总是要输入一个时间,而不仅仅是指定的一天。 Is it possible automatically set the time to 00:00 when the user only enters the date?
当用户只输入日期时,是否可以自动将时间设置为00:00?
Thanks for your help. 谢谢你的帮助。
protected function beforeSave()
{
if ( strpos(trim(this->date_field), ' ') !== false ) {
$this->date_field = sprintf('%s 00:00', $this->date_field);
}
return parent::beforeSave();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.