0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

created_atを○年○月○日と表記したい

Posted at

やりたい事
・投稿した日付を○年○月○日の表記にする事

経緯
・オリジナルアプリDayLogを作成中に変更する必要ができたから

試した事
<%= @day.created_at.strftime('%Y%M%D') %>と記述
→20205211/11/11と表示された。

原因は'%D'は'%d%m%y'と同値で、%Mは月(month)では無く時間(minutes)を表す表現だった。
参考記事
https://linuxjm.osdn.jp/html/LDP_man-pages/man3/strftime.3.html

結果
<%= @day.created_at.strf("%Y年%-m月%-d日") %>
と記述したら2020年11月18日と表示されて解決!

*%dの場合は09月、%-dの場合は9月と表示される(%d,%-dでも同じ)
参考記事
https://qiita.com/koda_7932/items/c54978483a002d75ea42

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?