1. The code is implemented as follows
use yii\base\InvalidArgumentException;
use yii\validators\DateValidator;
$validator = new DateValidator(['type' => DateValidator::TYPE_TIME, 'format' => 'H:i']);
if (!$validator->validate($this->value, $error)) {
throw new InvalidArgumentException($surveyFormField['name'] . '验证失败:' . $error);
}
2. But the verification failed, as shown in Figure 1

{
"code": 10500,
"message": "时间验证失败:属性 该输入 的格式无效。"
}
3. Since the format of H:I is the format in PHP. Set the string starting with php: to represent the date-time format that PHP can recognize. Verification passed. as shown in Figure 2

use yii\base\InvalidArgumentException;
use yii\validators\DateValidator;
$validator = new DateValidator(['type' => DateValidator::TYPE_TIME, 'format' => 'php:H:i']);
if (!$validator->validate($this->value, $error)) {
throw new InvalidArgumentException($surveyFormField['name'] . '验证失败:' . $error);
}
PHP / Laravel / Yii2 Legacy Project Maintenance & Long-Term Technical Support
If your PHP / Laravel / Yii2 project is already in production but needs bug fixing, API troubleshooting, performance optimization, developer handover support, or long-term maintenance, feel free to contact me for remote technical support.
Ideal For:
✅ PHP legacy systems without active maintenance
✅ Laravel / Yii2 project bug fixes
✅ Admin panel feature iterations
✅ RESTful API troubleshooting
✅ MySQL / Redis / Nginx performance issues
✅ Long-term remote part-time maintenance
We can start with a small task:
✅ Production error troubleshooting
✅ API issue analysis
✅ Slow query and performance bottleneck diagnosis
✅ Initial code structure review
✅ Deployment environment and log inspection
If you would like to discuss your project, please contact me and mention: PHP Maintenance Consultation.
Contact Me:
Telegram: @shuijingwan
WeChat: 13980074657
Email: shuijingwanwq@gmail.com


Leave a Reply