The
fs.futimes() method is used to asynchronously change the modification and access timestamps of given file descriptor. The timestamps can be specified using a number, string, or Date object. An error would be thrown if the timestamp cannot be converted to a proper number, or is NaN, Infinity or -Infinity.
Syntax:
fs.futimes( fd, atime, mtime, callback )
Parameters: This method accepts four parameters as mentioned above and described below:
- fd: It is an integer that denotes the file descriptor of the file whose timestamps have to be changed.
- atime: It is number, string or Date object that denotes the new access timestamp to be set.
- mtime: It is number, string or Date object that denotes the new modification timestamp to be set.
- callback: It is a function that would be called when the method is executed.
- err: It is an error that would be thrown if the method fails.
Below examples illustrate the
fs.futimes() method in Node.js:
Example 1:
Output:
Details before changing time:
Modification Time: 2020-05-25T15:59:10.807Z
Access Time: 2020-05-25T15:59:10.807Z
Details after changing time:
Changed Modification Time: 2020-05-25T16:01:34.915Z
Changed Access Time: 2020-05-25T16:01:34.915Z
Example 2:
Output:
Details before changing time:
Modification Time: 2020-05-25T16:06:28.977Z
Access Time: 2020-05-25T16:06:28.977Z
Details after changing time:
Changed Modification Time: 2019-03-31T22:43:20.000Z
Changed Access Time: 2019-04-12T02:42:40.000Z
Reference: https://nodejs.org/api/fs.html#fs_fs_futimes_fd_atime_mtime_callback