[RUBY] Use of Date class

Overview

・ Easy to use complicated concept of date ・ Date and time can be output

Preparation

-Call the date class from the outside with the require method

require "date"

today method

-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

_wday method _

-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

Remarks

(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 ”

* If you find something wrong or something like this, thank you.

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

Use of Date class
[Java] How to use compareTo method of Date class
Proper use of interface and abstract class
About date / time type of Doma2 entity class
[Java] How to use Calendar class and Date class
Output of the day of the week using Ruby's Date class
Use of Abstract Class and Interface properly in Java
Handling of date and time in Ruby. Use Date and Time properly.
[GCD] Basics of DispatchQueue class
Conversion of String, Date, LocalDate
Example of using abstract class
How to use java class
[Java] Comparator of Collection class
Trap of asList of Arrays class
Use @ValueSource of ParametrisedTest of JUnit5
Summary of Java Math class
When using the constructor of Java's Date class, the date advances by 1900.
[Ruby] Display today's day of the week using Date class
Get date without using Calendar class
Various methods of Java String class
Use enum instead of int constant
How to use the wrapper class
Proper use of redirect_to and render
How to use setDefaultCloseOperation () of JFrame
[Ruby] Date, Time, Datetime class basics
[Java] How to use LinkedHashMap class
From introduction to use of ActiveHash
Various methods of the String class
java (use class type for field)
[Spring Boot] Role of each class
Proper use of Mockito and PowerMock
Your use of JobScheduler is wrong
How to use class methods [Java]
[Java] How to use Math class
[Java] How to use the File class
[Java] How to use the HashMap class
Item 36: Use EnumSet instead of bit fields
[Java] Inheritance and structure of HttpServlet class
Explanation of Ruby Time and Date objects
Item 71: Avoid unnecessary use of checked exceptions
[For myself] Transfer of Servlet class processing
Item 37: Use EnumMap instead of ordinal indexing
Item 72: Favor the use of standard exceptions
[Java] [Maven3] Summary of how to use Maven3
[Processing × Java] How to use the class
How to use Java Scanner class (Note)
[Java] How to use the Calendar class
[Java] Get the date with the LocalDateTime class
[Java] Why use StringUtils.isEmpty () instead of String.isEmpty ()
[Java] Calculate the day of the week from the date (Calendar class is not used)