Home >Web Front-end >JS Tutorial >Instructions for using the fs.utimes method in node.js_node.js

Instructions for using the fs.utimes method in node.js_node.js

WBOY
WBOYOriginal
2016-05-16 16:27:061397browse

Method description:

Modify file timestamp asynchronously.

Grammar:

Copy code The code is as follows:

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

Since this method belongs to the fs module, the fs module needs to be introduced before use (var fs= require(“fs”) )

Receive parameters:

path File path

mtime Modification time, indicating the time and date when the file was modified. When the content of the file changes, the modification date of the file will be updated

atime access time, indicating the time and date when the file was last accessed. Every time an application or service uses a system call to read a file, the file's access time is updated.

callback Callback, passing an exception parameter err

Example:

Copy code The code is as follows:

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

Source code:

Copy code The code is as follows:

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);
};
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn