【发布时间】:2017-12-09 05:25:21
【问题描述】:
我的 db 表列名称是 hora (translation:hour): 输入时间。 (Postgres)。 我使用 Ruby 5.1 开发我的 API 我已经安装了 gem 主动模型序列化程序。我的问题是它以这种格式向我显示字段:“hora”:“2000-01-01T11:40:00Z”,但我只需要像这样的小时和分钟:11:40。 这是我的实际输出 json {"fecha":"2016-08-02","hora":"2000-01-01T11:40:00Z","importe":"86.0","medico":....}。
我需要这个: {"fecha":"2016-08-02","hora":"11:40","importe":"86.0","medico":...}
my table
|hora |
|time withotu time zone|
| 09:30:00 |
| 11:40:00 |
| 10:10:00 |
mycontroller#show
# GET /atencions/1
def show
render json: @atencion
end
my model
class Atencion < ApplicationRecord
self.table_name = "atencion"
belongs_to :medico
belongs_to :paciente_planobrasocial
end
my model serializer
class AtencionSerializer < ActiveModel::Serializer
belongs_to :medico
belongs_to :paciente_planobrasocial
attributes :fecha, :hora, :importe
end
有可能吗?我如何以及在哪里可以更改时间的格式... 提前谢谢...
【问题讨论】:
标签: ruby api time-format