Ocaml's Unix
module provides a stat
function, which returns a record with a float st_mtime
member.
This seems to always be second-level precision, even on Linux, which supports sub-second precision. The fact that it's a float and not an int gives me hope that it's possible to get a subsecond-precision time out of it (or something like it), but I don't know how.
I'm happy to use additional OPAM libraries. I'm using Batteries already, so I wouldn't want to also have to use e.g Jane Street Core - but smaller libraries are fine.
This is the script I used to test:
#!/usr/bin/env ocamlscript
Ocaml.packs := ["unix"]
--
open Unix
open Printf
let () =
let this_file = Array.get Sys.argv 0 in
let stats = Unix.stat this_file in
printf "mtime: %f" stats.st_mtime
when run on my Linux (x86_64) machine, it prints:
mtime: 1388567583.000000
Python has no trouble getting a sub-second mtime
, so my OS and FS definitely support it.