Skip to main content

Working With Dates And Times In Ruby — Part 1 MCQs with Explanations

Practice high-yield Programming & Software Development MCQs on Working With Dates And Times In Ruby — Part 1 with worked academic solutions for FPSC, PPSC, NTS, NITB, PTS.

Questions
40
Difficulty Level
Exam-Level
Target Exams
FPSC, PPSC, NTS...
Estimated Time
48 mins
Exam-Level FPSC PPSC NTS NITB PTS
Verified for Commission Syllabus • Oct 14, 2026
40

Verified Practice Questions

Interactive test mode with detailed academic worked solutions

Live Progress | 0/40 answered
✓ 0 correct ✗ 0 wrong 0% score
Question 1 of 40
★ FPSC ★ PPSC

How do you create a new Date object representing the current date in Ruby?

Question 2 of 40
★ FPSC ★ PPSC

What does the strftime method do in Ruby when applied to a Time object?

Question 3 of 40
★ FPSC ★ PPSC

Which method is used to subtract a number of days from a Date object in Ruby?

Question 4 of 40
★ FPSC ★ PPSC

What is the purpose of the strptime method in Ruby?

Question 5 of 40
★ FPSC ★ PPSC

Which method is used to add a number of months to a Date object in Ruby?

Question 6 of 40
★ FPSC ★ PPSC

What is the purpose of the Time.now method in Ruby?

Question 7 of 40
★ FPSC ★ PPSC

How do you find the difference in seconds between two Time objects in Ruby?

Question 8 of 40
★ FPSC ★ PPSC

What does the zone method return for a Time object in Ruby?

Question 9 of 40
★ FPSC ★ PPSC

How do you convert a Date object to a string in Ruby?

Question 10 of 40
★ FPSC ★ PPSC

Which method is used to find the number of days between two Date objects in Ruby?

Question 11 of 40
★ FPSC ★ PPSC

What does the to_date method do when applied to a Time object in Ruby?

Question 12 of 40
★ FPSC ★ PPSC

How do you find the number of seconds since the Unix epoch for a Time object in Ruby?

Question 13 of 40
★ FPSC ★ PPSC

Which method is used to check if a Time object occurs after another Time object in Ruby?

Question 14 of 40
★ FPSC ★ PPSC

What does the utc_offset method return for a Time object in Ruby?

Question 15 of 40
★ FPSC ★ PPSC

How do you find the number of months between two Date objects in Ruby?

Question 16 of 40
★ FPSC ★ PPSC

How do you find the day of the week for a given Date object in Ruby?

Question 17 of 40
★ FPSC ★ PPSC

What is the purpose of the zone method for a DateTime object in Ruby?

Question 18 of 40
★ FPSC ★ PPSC

How do you convert a Time object to the local time zone in Ruby?

Question 19 of 40
★ FPSC ★ PPSC

Which method is used to calculate the difference in years between two Date objects in Ruby?

Question 20 of 40
★ FPSC ★ PPSC

What does the month method return for a Date object in Ruby?

Question 21 of 40
★ FPSC ★ PPSC

How do you find the number of hours between two Time objects in Ruby?

Question 22 of 40
★ FPSC ★ PPSC

What is the purpose of the parse method for parsing dates in Ruby?

Question 23 of 40
★ FPSC ★ PPSC

Which method is used to find the number of weeks between two Date objects in Ruby?

Question 24 of 40
★ FPSC ★ PPSC

What does the start_of_week method do for a Date object in Ruby?

Question 25 of 40
★ FPSC ★ PPSC

How do you find the number of minutes between two Time objects in Ruby?

Question 26 of 40
★ FPSC ★ PPSC

What is the purpose of the xmlschema method for formatting date and time strings in Ruby?

Question 27 of 40
★ FPSC ★ PPSC

How do you find the number of seconds between two Time objects in Ruby?

Question 28 of 40
★ FPSC ★ PPSC

What does the ordinal method return for a Date object in Ruby?

Question 29 of 40
★ FPSC ★ PPSC

How do you find the number of days between two Date objects in Ruby?

Question 30 of 40
★ FPSC ★ PPSC

What is the purpose of the zone method for a Date object in Ruby?

Question 31 of 40
★ FPSC ★ PPSC

How do you find the number of days in the current month in Ruby?

Question 32 of 40
★ FPSC ★ PPSC

What does the utc method do for a Time object in Ruby?

Question 33 of 40
★ FPSC ★ PPSC

How do you find the number of weeks in the current year in Ruby?

Question 34 of 40
★ FPSC ★ PPSC

How do you find the number of seconds between two DateTime objects in Ruby?

Question 35 of 40
★ FPSC ★ PPSC

What does the at_beginning_of_day method do for a DateTime object in Ruby?

Question 36 of 40
★ FPSC ★ PPSC

How do you find the number of milliseconds between two Time objects in Ruby?

Question 37 of 40
★ FPSC ★ PPSC

What is the purpose of the beginning_of_week method for a Date object in Ruby?

Question 38 of 40
★ FPSC ★ PPSC

How do you find the number of hours between two DateTime objects in Ruby?

Question 39 of 40
★ FPSC ★ PPSC

What does the advance method do for a Date object in Ruby?

Question 40 of 40
★ FPSC ★ PPSC

What is the purpose of the seconds_since_midnight method for a Time object in Ruby?

✓ Link copied to clipboard
Continue Your Practice

Advance Html — Part 1

Master the next curriculum module with 40 exam-standard MCQs.

Next Practice Set →

💡 Examiner's Advisory for Programming & Software Development

In competitive commission exams (FPSC, PPSC, KPPSC, SPSC, CSS, PMS), questions are frequently phrased with distractor options designed to catch rote learners. Whenever you answer an MCQ, read the Detailed Academic Explanation and Conceptual Anchor to understand why the remaining options are incorrect.

More Modules in Programming & Software Development

View All →
📚

Study Guides

Topic summaries and syllabus breakdown

Explore Guides →
🎯

Complete Library

Search through 78,000+ verified MCQs

Browse Library →
📱

Mobile App

Offline mock tests and instant bookmarks

Get Mobile App →