Instructions for the fs.utimes method in node.js

  • 2020-05-05 10:55:51
  • OfStack

method description:

Modify the file timestamp asynchronously.

syntax:


fs.utimes(path, atime, mtime, callback)

Since this method belongs to the fs module, it is necessary to introduce the fs module (var fs= require(" fs "))

before using it

receive parameters:

path                  

mtime               modification time, indicates the time and date the file was modified. When the contents of the file change, the modification date of the file is updated with

atime                 access time, which indicates the time and date the file was last accessed. Each time an application or service reads a file using a system call, the access time of the file is updated.

callback         callback, passing an exception parameter err

example:


var fs = require('fs');
fs.utimes('125.txt', atime, mtime, function(err){
 if(err){
  throw err;
 }
 console.log('time update');
})

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);
};


Related articles: