stats.ctimeNs屬性是fs.Stats類的內置應用程序編程接口,用於獲取自POSIX紀元以來最後一次更改文件狀態的時間戳(以納秒表示)。
用法:
stats.ctimeNs;
參數:屬性沒有任何參數,但是在創建統計信息時,對象{bigint:true}必須作為選項傳遞。
返回值:它返回一個數字或BigInt值,該值表示自POSIX時期以來最後一次更改文件狀態時的時間戳(以納秒表示)。
以下示例說明了Node.js中stats.ctimeNs屬性的用法:
範例1:
// Node.js program to demonstrate the
// stats.ctimeNs property
// Accessing fs module
const fs = require('fs');
// Calling stats.ctimeNs property
// from fs.Stats class using stat
fs.stat('./', { bigint:true }, (err, stats) => {
if (err) throw err;
// The timestamp when the file status
// has been changed last time (in NS)
console.log("Using stat:" + stats.ctimeNs);
});
// Using lstat
fs.lstat('./filename.txt',
{ bigint:true }, (err, stats) => {
if (err) throw err;
// The timestamp when the file status
// has been changed last time (in NS)
console.log("Using lstat:" + stats.ctimeNs);
});
輸出:
Using stat:1592665604516105.7 Using lstat:1592665807796265
範例2:
// Node.js program to demonstrate the
// stats.ctimeNs property
// Accessing fs module
const fs = require('fs').promises;
// Calling fs.Stats stats.ctimeNs
(async () => {
const stats = await fs.stat(
'./filename.txt', { bigint:true });
// The timestamp when the file
// status has been changed last
// time (in NS)
console.log("Using stat synchronous:"
+ stats.ctimeNs);
})().catch(console.error)
輸出:
Using stat synchronous:1592665807796265
注意:上麵的程序將通過使用以下命令進行編譯和運行node filename.js
命令並正確使用file_path。
參考: https://nodejs.org/api/fs.html#fs_stats_ctimens
相關用法
- Node.js GM magnify()用法及代碼示例
- Node.js GM modulate()用法及代碼示例
- Node.js GM minify()用法及代碼示例
- Node.js GM write()用法及代碼示例
- Node.js GM whiteThreshold()用法及代碼示例
- Node.js GM whitePoint()用法及代碼示例
- Node.js GM spread()用法及代碼示例
- Node.js GM despeckle()用法及代碼示例
- Node.js GM crop()用法及代碼示例
- Node.js GM gaussian()用法及代碼示例
- Node.js GM emboss()用法及代碼示例
- Node.js GM solarize()用法及代碼示例
- Node.js GM shave()用法及代碼示例
- Node.js GM threshold()用法及代碼示例
- Node.js GM recolor()用法及代碼示例
注:本文由純淨天空篩選整理自anwesha0107大神的英文原創作品 Node.js | stats.ctimeNs Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。