私は次のものを持っています:
@comment.created_at.strftime("%I:%M %p %b %d")
どの出力: 10:32 AM Dec 19
次のように小文字の am を出力したい: 10:32am Dec 19
ルビー/レールでそれを行う方法についてのアイデアはありますか?
ありがとう
私は次のものを持っています:
@comment.created_at.strftime("%I:%M %p %b %d")
どの出力: 10:32 AM Dec 19
次のように小文字の am を出力したい: 10:32am Dec 19
ルビー/レールでそれを行う方法についてのアイデアはありますか?
ありがとう
%p を使用する代わりに %P を使用してみてください
%p の代わりに %P を使用します。これは ruby 1.9 で動作しますが、1.8 では、.sub(' AM ', ' am ').sub(' PM ', ' pm ')
または同様のものを使用する必要があります。
それらを異なる変数に保存して、次のようにすることができます。
a = @comment.created_at.strftime("%I:%M")
b = @comment.created_at.strftime("%P").downcase
c = @comment.created_at.strftime("%b %d")
e = a+b+" "+c #=> 10:32am Dec 19
ruby 1.9 では %p の代わりに %P を使用できるようで、スペースを削除することを忘れないでください
@comment.created_at.strftime("%I:%M%P %b %d") =>12 月 19 日午前 10 時 32 分