・ Easy to use complicated concept of date ・ Date and time can be output
-Call the date class from the outside with the require method
require "date"
-Methods often used in the date class ・ Automatically calculates and outputs the "today's" date
require "date"
day = Date.today
#Assign to a variable called day
puts day
#result
2020-10-24
-The day of the week can be output as an integer from 1 to 6 in the order of Sunday or Saturday. Sunday = 0 Monday = 1 Tuesday = 2 Wednesday = 3 Thursday = 4 Friday = 5 Saturday = 6
require "date"
day = Date.today.wday
puts day
#Result (for Sunday)
0
(Example) Sunday and Saturday are "Today is XX day of the week. It's a holiday. " Other days are "Today is XX day. It's work ”
require"date"
day = Date.today.wday
wday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
if day == 6 or 0
puts "today#{wday[day]}.. Break time! !!"
else
puts "today#{wday[day]}.. It is the job"
end
Recommended Posts