gpt4 book ai didi

mysql - Rails 仅以以下格式存储和检索时间 : hh:mm:ss

转载 作者:行者123 更新时间:2023-11-29 21:03:40 25 4
gpt4 key购买 nike

我像这样生成了我的模型:

class CreateMyModel < ActiveRecord::Migration
def change
create_table :my_model do |t|
t.references :place, index: true
t.time :time_first
t.time :time_second

t.timestamps
end
end
end

将模型保存到 mysql 工作正常。时间列填充为 hh:mm:ss,这很好。但是当我从 mysql 检索条目时,它以某种方式包含 2000-01-01 的日期,例如:

2000-01-01T17:00:00Z

如何检索时间列为 hh:mm:ss?

我正在像这样查询表条目:

my_model = MyModel.find(id)
print my_model.to_json#here time_first and time_second include date.

最佳答案

用它来表示时间(以分钟和小时为单位):

my_model.time_second.strftime("%H:%M %S %p")

关于mysql - Rails 仅以以下格式存储和检索时间 : hh:mm:ss,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37003628/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com