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
file.c
View on GitHub ↗
static VALUE
rb_stat_mtime(VALUE self)
{
return stat_time(statx_mtimespec(get_stat(self)));
}
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.