Understanding how Ruby handles time and dates is essential for efficient programming. These MCQs will test your knowledge on Time and Date classes, formatting, parsing, and performing date/time calculations in Ruby.
Date class in Ruby represent?
Time class in Ruby?
Date object for the current date in Ruby?
Date.nowDate.todayDate.currentDate.newTime.nowTime.currentTime.newTime.todayDate object to display in a custom format in Ruby?
Date.to_s(format)Date.strftime(format)Date.format(format)Date.custom_format(format)Date object in Ruby?
Date.parse("2024-11-19")Date.strptime("2024-11-19")Date.create("2024-11-19")Date.new("2024-11-19")strftime represents the full month name in Ruby?
%m%b%B%dTime object to a string in a specific format?
Time.to_s(format)Time.strftime(format)Time.custom_format(format)Time.format(format)Time.now.strftime("%Y-%m-%d %H:%M:%S")?
YYYY-MM-DD HH:MM:SS formatDD-MM-YYYY HH:MM:SS formatMM-DD-YYYY HH:MM:SS formatHH:MM:SS YYYY-MM-DD formatDate object in Ruby?
date + 5date.add(5)date.days(5)date.plus(5)Time objects?
Time.diffTime.subtractTime.agoTime - TimeTime.now - Time.now in Ruby?
0Date objects in Ruby?
date1.days_between(date2)date1 - date2date1.diff(date2)date1.days_until(date2)Time object?
Time.seconds_toTime.diff_secondsTime - TimeTime.seconds_sinceDate object in Ruby?
date - 3.monthsdate.months_ago(3)date.subtract(3.months)date.minus(3.months)date.next_month_begindate.next_monthdate.next_month_startdate.beginning_of_next_monthTime.start_of_weekTime.beginning_of_weekTime.current_week_startTime.now.beginning_of_weekTime.now in Ruby?
Time.now in Ruby?
Time.now.in_time_zone('PST')Time.now.set_time_zone('PST')Time.now.timezone('PST')Time.now.set_zone('PST')Time object to UTC in Ruby?
time.utctime.to_utctime.convert_to_utctime.in_utcTime object is in the UTC time zone in Ruby?
time.utc?time.is_utc?time.in_utc?time.timezone == 'UTC'Time.now.utc? in Ruby?
true if the current time is in UTCfalse if the current time is not in UTCtrue if the time is converted to UTCfalse if the time is converted to local timeTime object in Ruby?
time + 2.hourstime.add(2.hours)time.plus(2.hours)time + (2 * 60 * 60)Time object to the local time zone in Ruby?
time.localtimetime.in_local_timetime.to_localtime.convert_to_localDate.valid?Date.valid_date?Date.parseDate.valid_string?Time object represents a future date in Ruby?
time.is_future?time.future?time > Time.nowtime.is_after_now?Date.valid_date? do in Ruby?
true if the date is valid, false otherwiseDate objectnil if the date is invalidDate object represents a leap year in Ruby?
date.leap_year?date.is_leap_year?date.year_is_leap?date.is_leap?time.between?(start_time, end_time)time.is_between?(start_time, end_time)time.validate_range(start_time, end_time)time.check_range(start_time, end_time)| Qno | Answer (Option with text) |
|---|---|
| 1 | B) Time |
| 2 | C) Only the date, excluding the time |
| 3 | A) It includes both the date and the time information |
| 4 | B) Date.today |
| 5 | A) Time.now |
| 6 | B) Date.strftime(format) |
| 7 | A) Date.parse(“2024-11-19”) |
| 8 | C) %B |
| 9 | B) Time.strftime(format) |
| 10 | A) Current time in YYYY-MM-DD HH:MM:SS format |
| 11 | A) date + 5 |
| 12 | D) Time – Time |
| 13 | B) 0 |
| 14 | B) date1 – date2 |
| 15 | C) Time – Time |
| 16 | B) date.months_ago(3) |
| 17 | D) date.beginning_of_next_month |
| 18 | D) Time.now.beginning_of_week |
| 19 | C) System’s local time zone |
| 20 | A) Time.now.in_time_zone(‘PST’) |
| 21 | A) time.utc |
| 22 | A) time.utc? |
| 23 | A) true if the current time is in UTC |
| 24 | A) time + 2.hours |
| 25 | A) time.localtime |
| 26 | B) Date.valid_date? |
| 27 | C) time > Time.now |
| 28 | A) It returns true if the date is valid, false otherwise |
| 29 | A) date.leap_year? |
| 30 | A) time.between?(start_time, end_time) |