You can use the File
class in Ruby to get the last access time of a file. Here's an example for a JSON file:
main.rb336 chars12 lines
In the code above, we first require the json
module for working with JSON files.
We then specify the filename
variable to the path of the JSON file you want to get the last access time for.
We use the File.atime
method to get the last access time of the file in a format similar to the Ruby Time
class.
Finally, we convert the time to a more readable format using DateTime.parse
and strftime
, and then output it to the console.
gistlibby LogSnag