[英]Rails: Show time when it's not 00:00 or 12:00 from a DateTime field
In my rails app I have a datetime field, which defaults to 12:00 when time is not specified. 在我的Rails应用程序中,我有一个datetime字段,如果未指定时间,则默认为12:00。 I only intend to display time is not 00:00 or 12:00, if it's 00:00 then I only want to display date and not time. 我只打算显示时间不是00:00或12:00,如果是00:00,那么我只想显示日期而不是时间。 It there's time other than 12:00 or 00:00 then I want to display both. 除了12:00或00:00以外,我想同时显示两者。
You can do this, 你可以这样做,
time = datetime_field.strftime("%I:%M")
if time == '12:00'
# do something
else
# do something else
end
Hope that helps! 希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.