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

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

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

Method description:

Synchronized version of utimes(), which modifies file timestamps synchronously.

Grammar:

Copy code The code is as follows:

fs.utimesSync(path, atime, mtime)

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.

Example:

Copy code The code is as follows:

var fs = require('fs');
fs.utimesSync('125.txt', atime, mtime);

Source code:

Copy code The code is as follows:

fs.utimesSync = function(path, atime, mtime) {
nullCheck(path);
atime = toUnixTimestamp(atime);
mtime = toUnixTimestamp(mtime);
binding.utimes(pathModule._makeLong(path), atime, mtime);
};
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