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#mtime

() -> ::Time
mtime → time

Returns a new Time object containing the modification time for self; see Modification Time:

Example
path = 't.tmp'
file = File.new(path, 'w+')
file.mtime # => 2026-09-19 08:41:29.357110007 -0500
file.write('foo')
file.flush
file.mtime # => 2026-09-19 08:41:46.321965574 -0500
File.unlink(path)
See also .mtime #lstat #size #flock also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0