LoginSignup
1
0

More than 1 year has passed since last update.

Dateクラスで曜日を表示させる

Last updated at Posted at 2021-05-07

はじめに

アウトプット用に記述します。

Dateクラスについて

DateクラスとはRubyの標準ライブラリの機能です。

require "date"

下記で今日の日付を表示する事ができます

require "date"

puts Date.today

#今日が2021年5月7日のため
=>2021-05-07

曜日を表す時は...

puts Date.today.wday

=> 5
#数字?

数字が出てきますので、配列で曜日の配列もセットで作ります。

day = Date.today.wday

week =["日曜日", "月曜日", "火曜日", "水曜日", "木曜日", "金曜日", "土曜日"]

#dayを添字にする
puts "#{week[day]}"

#今日が金曜日のため
=> 金曜日
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