1
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 5 years have passed since last update.

created_atを西暦/月/日 XX:YYと表示したい #CSS #Ruby on Rails #Progate

Posted at

やりたいこと

・投稿した日付を 西暦/月/日 XX:YY と表示したい

経緯

・ProgateでRuby,Ruby on Rails,HTTM&CSSを学習し、現在tweet_appを再現中!
その中でつまずいた箇所の備忘として。

解決方法・いろいろな表示方法

◆投稿日時を表示(例:2019/10/23 15:03)
今回の表示方法であれば、下記のようにすればOK

CSS
<%= 変数名.created_at.strftime('%Y/%m/%d %H:%M') %>

◆何分前、何時間前に投稿したかを表示(例:30秒以内、約1ヶ月・・・)

CSS
<%= time_ago_in_words(post.created_at) %>

※これだと英語表記になるので、日本語にしたい場合はこちらを参考に

1
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
1
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?