سؤال

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.

هل كانت مفيدة؟

المحلول 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

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top