Rails:为什么时间数据类型从2000年1月1日开始 [英] Rails: why time datatype start at 1/1/2000
问题描述
我有一列只想存储时间(小时,分钟,秒)。例如,这里是一次迁移:
add_column:products,:start_hour,:time
当我插入数据库 start_hour
时,始终以 1/1开头/ 2000
,例如: 2000-01-01 01:19:00 +0700
。请为我解释原因。
在Ruby或Rails中没有每日班级,因此ActiveRecord表示 time
列以及datetime / timestamp类。
如果在数据库内部查找时没有ActiveRecord,Rails或Ruby杂音顺便说一下,您会看到 HH:MM:SS
一天中的时间值。但是,当ActiveRecord从数据库中拉出 time
时,它将date组件设置为2000-01-01,因为datetime必须具有日期,而AR会选择该日期。 / p>
每次在Ruby中使用 start_hour
时,您都必须忽略日期部分。
I have a column that I only want to store time (hour, minute, second). for example here is one migration:
add_column :products, :start_hour, :time
When I insert to database start_hour
always start with 1/1/2000
for example: 2000-01-01 01:19:00 +0700
. Please explain for me why.
There is no time-of-day class in Ruby or Rails so ActiveRecord represents time
columns with datetime/timestamp classes.
If you look inside the database without any of the ActiveRecord, Rails, or Ruby noise in the way, you'll see an HH:MM:SS
time-of-day value. But when ActiveRecord pulls a time
out of the database, it sets the date component to 2000-01-01 because a datetime has to have a date and AR picks that one.
Any time you work with a start_hour
in Ruby you'll have to ignore the date component.
这篇关于Rails:为什么时间数据类型从2000年1月1日开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!