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 1 year has passed since last update.

【Ruby】日時を任意のフォーマットで出力する

Posted at

概要

Rubyで日時を出力する時の忘備録として記載する。
指定方法により時刻を format 文字列に従って文字列に変換した結果を返します。

p t = Time.new(2001,2,3,4,5,6,"+09:00")  # => 2001-02-03 04:05:06 +0900
p t.strftime("Printed on %m/%d/%Y")      # => "Printed on 02/03/2001"
p t.strftime("Printed on %m/%-d/%_6Y")   # => "Printed on 02/3/  2001"
p t.strftime("at %I:%M%p")               # => "at 04:05AM"
p t.strftime("at %I:%M%#p")              # => "at 04:05am"
p t.strftime("%Y%m%d")                           # => 20010203                  Calendar date (basic)

参考資料

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?