stats.atime屬性是fs.Stats類的內置應用程序編程接口,用於獲取上次訪問文件的時間和日期。
用法:
stats.atime;
參數:屬性沒有任何參數。
返回值:它返回一個Date,它表示上次訪問文件時的時間和日期。
以下示例說明了Node.js中stats.atime屬性的用法:
範例1:
// Node.js program to demonstrate the
// stats.atime Property
// Accessing fs module
const fs = require('fs');
// Calling fs.Stats stats.atime
// using stat
fs.stat('./', (err, stats) => {
if (err) throw err;
// The time and date when
// the file is last accessed
console.log("Using stat:" + stats.atime);
});
// Using lstat
fs.lstat('./filename.txt', (err, stats) => {
if (err) throw err;
// The time and date when the
// file is last accessed
console.log("Using lstat:" + stats.atime);
});
輸出:
Using stat:Sun Jun 21 2020 00:54:20 GMT+0530 (India Standard Time) Using lstat:Sun Jun 21 2020 01:00:52 GMT+0530 (India Standard Time)
範例2:
// Node.js program to demonstrate the
// stats.atime Property
// Accessing fs module
const fs = require('fs').promises;
// Calling fs.Stats stats.atime
(async () => {
const stats = await fs.stat('./filename.txt');
// The date and time when the
// file is last accessed
console.log("Using stat synchronous:"
+ stats.atime);
})().catch(console.error)
輸出:
Using stat synchronous:Sun Jun 21 2020 01:00:52 GMT+0530 (India Standard Time)
注意:上麵的程序將通過使用以下命令進行編譯和運行node filename.js
命令並正確使用file_path。
參考: https://nodejs.org/api/fs.html#fs_stats_atime
相關用法
- Node.js GM orderedDither()用法及代碼示例
- Node.js GM raise()用法及代碼示例
- Node.js GM resize()用法及代碼示例
- Node.js GM roll()用法及代碼示例
- Node.js GM quality()用法及代碼示例
- Node.js GM segment()用法及代碼示例
- Node.js GM paint()用法及代碼示例
- Node.js GM drawBezier()用法及代碼示例
- Node.js GM drawPolyline()用法及代碼示例
- Node.js GM drawLine()用法及代碼示例
- Node.js GM drawArc()用法及代碼示例
- Node.js GM spread()用法及代碼示例
- Node.js GM drawCircle()用法及代碼示例
注:本文由純淨天空篩選整理自anwesha0107大神的英文原創作品 Node.js | stats.atime Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。