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 # from  w  w w .  ja v  a2 s .c o  m
puts t.min 
puts t.sec

Result

Related Topic