Question

The times returned by Node's fs.stat seem to have one-second resolution even on file systems that support nanosecond resolution, like ext4.

var fs = require('fs')
var stats = fs.statSync('.')
stats.mtime.getMilliseconds() // => always 0

How do I get stat times with better resolution? Nanoseconds would be ideal, but milliseconds or microseconds is OK too.

Was it helpful?

Solution 2

As of Node v8.10 millisecond and nanosecond resolution time is available as separate properties:

 stats.mtimeMs
 stats.ctimeMs
 stats.atimeMs

i.e.

stats.mtime.getMillieseconds() //546
stats.mtimeMs // 1391354639546.3066

OTHER TIPS

The solution is to upgrade Node. As of Node 0.11.0 (#3284, 51f128d), we get millisecond-resolution time:

var fs = require('fs')
var stats = fs.statSync('.')
stats.mtime.getMilliseconds() // => 367

I'm still not sure if there's a way to get nanoseconds, but getting milliseconds is a big improvement.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top