How to Check the Last Modified Time of a File in Julia
Description
Using the stat() function you can view a file’s metadata. The time the file was last modified is stored in the mtime property. However, stat() shows how long ago that was relative to now, and if you inspect info.mtime directly you only see a strange number.
julia> stat("test.txt")
StatStruct for "test.txt"
size: 82 bytes
device: 1692283895
inode: 26886
mode: 0o100666 (-rw-rw-rw-)
nlink: 1
uid: 0
gid: 0
rdev: 0
blksz: 4096
blocks: 0
mtime: (17 minutes ago)
ctime: (17 minutes ago)
julia> info.mtime
1.7514459083956373e9
This is because mtime is stored as a Unix timestamp. A Unix timestamp represents the number of seconds elapsed since 1970-01-01 00:00:00 UTC. Thus the result of the code above means that the file was last modified approximately 1,751,445,908.395637.3 seconds after 1970-01-01. To convert this into a human-readable form you should use the standard library Dates.
Code
You can use the function unix2datetime(). mtime itself can also be used as a function.
julia> mtime("test.txt")
1.7514459083956373e9
julia> using Dates
julia> test_mtime = unix2datetime(info.mtime)
2025-07-02T08:45:08.395
julia> Dates.format(test_mtime, "yyyy-mm-dd HH:MM:SS")
"2025-07-02 08:45:08"
Environment
- OS: Windows 11
- Version: Julia 1.11.3
