format.rb

Heads up: This description was created by AI and might not be 100% accurate.

This Ruby code snippet demonstrates obtaining the current time and formatting it as a string. Time.now gets the current date and time. strftime("%F") then formats this time object into a date string with the format “YYYY-MM-DD”.

Ruby code snippet

t = Time.now
#=> 2026-01-14 13:11:32.51563446 +0000
t.strftime("%F")
#=> "2026-01-14"

Executed with Ruby 4.0.1.