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.

Time, Dateオブジェクト

Last updated at Posted at 2019-03-15

#Timeオブジェクト

#現在時刻
puts Time.now

#タイムゾーン
puts Time.now.zone

#指定のTimeオブジェクトを生成する
datetime = Time.new(2019, 3, 15, 16, 30)
puts datetime

#フォーマットを定義できる
puts datetime.strftime('%Y年 %m月 %d日 %H: %Mmin')

# >>2019年 03月 15日 16: 30min

#Dateオブジェクト

#Dateライブラリを読み込まないと使えない
require 'date'

#今日の日付 todayメソッド
puts Date.today

#任意の日付でDateオブジェクトを作成
date = Date.new(2019, 3, 15)
puts date

#フォーマットを自分で定義
puts date.strftime('%Y年 %m月 %d日')
 
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?