我试图返回一个日期作为字符串,但从返回的小时中删除第一个0。Ruby/Rails - 解析日期时间
这是我使用的代码:
t = Time.new
current_date = Time.local(t.year, t.month, t.day, t.hour, t.min/30*30)
time_str = current_date.strftime("%I.%M+%p").downcase
puts time_str
Outputs:
03.00+pm
Expected output:
3.00+pm # need to remove the last zero from the hour(s)
由于返回的字符串是“3.00 + pm”,我不得不在末尾添加'strip!'。它的工作原理,谢谢! – fuzz 2011-12-22 04:22:40
不客气,不要忘记将它标记为未来访客帮助的接受答案。 – 2011-12-22 04:29:48