Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

File::Stat#mtime

() -> ::Time
mtime → time

Returns a new Time object containing the modification time of the object represented by self at the time self was created; see Snapshot:

Example
path = 't.tmp'
file = File.new(path, 'w+')
stat = File.stat(path)
stat.mtime        # => 2026-09-19 08:49:08.846933858 -0500
file.write('foo')
file.flush
File.mtime(path)  # => 2026-09-19 08:50:14.381365572 -0500
stat.mtime        # => 2026-09-19 08:49:08.846933858 -0500
stat = File.stat(path)
stat.mtime        # => 2026-09-19 08:50:14.381365572 -0500
File.unlink(path) # Clean up.
See also #mode #nlink #inspect #owned? also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0