Ruby - File Last Modified Time

Introduction

To get when a file was last modified, use File.mtime:

Demo

puts File.mtime("main.rb")

Result

The format of the preceding date is specific to Ruby version.

The time is returned as a Time object, so you can get more information directly:

Demo

t = File.mtime("main.rb") 
puts t.hour #  w w w  . ja  v a  2 s.co m
puts t.min 
puts t.sec

Result

Related Topic