1
1

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.

時間表示(strftime)

Posted at

使い方

strftime(フォーマット)
time = Time.now # Thu Dec 24 00:00:00 +0900 2011
time.strftime('%Y年%m月%d日 %H:%M:%S') # 2011年12月24日 00:00:00
%A	曜日の名称(Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday)
%a	曜日の省略名(Sun, Mon, Tue, Wed, Thu, Fri, Sat)
%B	月の名称(January, February, March, April, May, June, July, August, September, October, November, December)
%b	月の省略名(Jan, Feb, Mar, Aprm May, Jun, Jul, Aug, Sep, Oct, Nov, Dec)
%c	日付と時刻
%d	日(01-31)
%H	24時間制の時(00-23)
%I	12時間制の時(01-12)
%j	年中の通算日(001-366)
%M	分(00-59)
%m	月を表す数字(01-12)
%p	午前または午後(AM,PM)
%S	秒(00-60) (60はうるう秒)
%U	週を表す数。最初の日曜日が第1週の始まり(00-53)
%W	週を表す数。最初の月曜日が第1週の始まり(00-53)
%w	曜日を表す数。日曜日が0(0-6)
%X	時刻
%x	日付
%Y	西暦を表す数
%y	西暦の下2桁(00-99)
%Z	タイムゾーン
%%	パーセント文字

補足

・Ruby の strftime で月日や時刻の 0 埋めを行わない書式指定

Time.now.strftime('%Y/%-m/%-d %-H:%-M:%-S') #=> 2012/8/14 9:4:10

・リファレンス → https://docs.ruby-lang.org/ja/1.9.3/method/Time/i/strftime.html

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?