I am trying to import some data in from a flat file and am getting some odd results. When importing a time that is unattached to a date, why do I get a date inserted into this time as well?
我试图从平面文件导入一些数据,并得到一些奇怪的结果。导入未附加到日期的时间时,为什么还要在此时插入日期?
1.9.3-p286 :008 > v.arrival_time = Time.parse("10:10")
=> 2012-11-06 10:10:00 -0400
I'm guessing that there is only a way to keep the date by itself, but no way to keep the time by itself despite the active record column-type :time. Is there a way to keep them separate such as:
我猜测只有一种方法可以自己保留日期,但是尽管有活动记录列类型:时间,但没有办法保持时间。有没有办法让它们分开,例如:
1.9.3-p286 :002 > Date.parse("JAN 01 2000")
=> Sat, 01 Jan 2000
1 个解决方案
#1
8
The Time
object in Ruby uses "Unix Time" to store temporal points as seconds since January 1, 1970 00:00 UTC. Various methods such as strftime
merely change the format of the output, but not how the object is stored internally.
Ruby中的Time对象使用“Unix Time”将时间点存储为自1970年1月1日00:00 UTC以来的秒数。 strftime等各种方法只是改变了输出的格式,而不是内部存储对象的方式。
So you have a decision to make: keep your imported data as a Time object, and be mindful of what it actually contains, or import your data as a string but forgo all the lovely, useful features of Time
.
因此,您需要做出决定:将导入的数据保存为Time对象,并注意它实际包含的内容,或者将数据作为字符串导入,但要放弃Time的所有可爱,实用的功能。
#1
8
The Time
object in Ruby uses "Unix Time" to store temporal points as seconds since January 1, 1970 00:00 UTC. Various methods such as strftime
merely change the format of the output, but not how the object is stored internally.
Ruby中的Time对象使用“Unix Time”将时间点存储为自1970年1月1日00:00 UTC以来的秒数。 strftime等各种方法只是改变了输出的格式,而不是内部存储对象的方式。
So you have a decision to make: keep your imported data as a Time object, and be mindful of what it actually contains, or import your data as a string but forgo all the lovely, useful features of Time
.
因此,您需要做出决定:将导入的数据保存为Time对象,并注意它实际包含的内容,或者将数据作为字符串导入,但要放弃Time的所有可爱,实用的功能。