javascript - What format is used for nodejs fs.utimes -
in nodejs, arguments of fs.utimes
should written in format,e.g.atime
,mtime
.
api: fs.utimes(path, atime, mtime, callback)
those parameters javascript date
s, not strings.
please note atime, mtime , ctime instances of date object , compare values of these objects should use appropriate methods. general uses gettime() return number of milliseconds elapsed since 1 january 1970 00:00:00 utc , integer should sufficient comparison, there additional methods can used displaying fuzzy information. more details can found in mdn javascript reference page.
and source code:
fs.utimes = function(path, atime, mtime, callback) { callback = makecallback(callback); if (!nullcheck(path, callback)) return; binding.utimes(pathmodule._makelong(path), tounixtimestamp(atime), tounixtimestamp(mtime), callback); }; // converts date or number fractional unix timestamp function tounixtimestamp(time) { if (util.isnumber(time)) { return time; } if (util.isdate(time)) { // convert 123.456 unix timestamp return time.gettime() / 1000; } throw new error('cannot parse time: ' + time); }
which shows can javascript date or unix style numeric date.
this line important!!! return time.gettime() / 1000;
means if pass in number pass in unix style number milliseconds represented in 1/1000s different integer returned date.gettime()
Comments
Post a Comment