There is no problem not worth solving, and no technology not worth learning!

In Yii2, verify the implementation of the value of the time format 15:00

由于 H:i 的格式为 PHP 中的格式。设置以 php: 开头的字符串,用来表示PHP可以识别的日期时间格式。验证通过

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

但是验证失败
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

由于  H:i 的格式为 PHP 中的格式。设置以 php: 开头的字符串,用来表示PHP可以识别的日期时间格式。验证通过
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

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.