简体   繁体   English

如何使用php framework laravel 5.1在mysql中正确插入时间值?

[英]How to properly insert time values in mysql using php framework laravel 5.1?

Actually, I'm trying to insert some 'time' values in mysql database using laravel 5.1 eloquent. 实际上,我正在尝试使用laravel 5.1雄辩地在mysql数据库中插入一些“时间”值。 But I'm getting that ZERO time error. 但是我遇到了零时间错误。

I insert some time, like '06:55:00' and in the database shows '00:00:00'. 我插入一些时间,例如“ 06:55:00”,并在数据库中显示“ 00:00:00”。

So, I want to understand the better practices to insert datetime values and avoid this kind of errors. 因此,我想了解插入日期时间值并避免此类错误的更好做法。

Here the actual code that I'm working on: 这是我正在处理的实际代码:

$some_var = ModelClass::create([
                           'time1' => date('H:m:s', strtotime('06:30:00')),
                           'time2' => date('H:m:s', strtotime('14:55:00'))
                          ])->pluck('id');

And I got this in the database: 我在数据库中得到了这个:

id         |     time1     |      time2     |
 1         |   00:00:00    |    00:00:00    |

Thanks to samlev 感谢samlev

Using Carbon solved my problem, and looks like a good way to work with DateTime values. 使用Carbon可以解决我的问题,并且看起来是使用DateTime值的好方法。

If anybody else is has problems with another kind of php framework, maybe could use it too. 如果其他人对另一种php框架有疑问,也许也可以使用它。

just access carbon's page here. 只需在此处访问碳的页面即可。

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

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