process.uptime()方法是進程模塊的內置應用程序編程接口,用於獲取Node.js進程運行的秒數。
用法:
process.uptime();
參數:此方法不接受任何參數。
返回值:它返回一個浮點數,該數字指定Node.js進程正在運行的秒數。
以下示例說明了Node.js中process.uptime()方法的使用:
範例1:
// Node.js program to demonstrate the
// process.uptime() Method
// Allocating process module
const process = require('process');
// Printing the number of seconds
// the Node.js process is running
console.log(process.uptime());
輸出:
0.0842063
範例2:
// Node.js program to demonstrate the
// process.uptime() Method
// Allocating process module
const process = require('process');
// Checking whether the method
// exists or not
if (process.uptime) {
// Printing uptime() value
console.log("The number of seconds the"
+ " Node.js process is running:"
+ process.uptime() + " seconds");
var i = 1000000;
while(i--);
console.log("The number of seconds the"
+ " Node.js process is running:"
+ process.uptime() + " seconds");
console.log("In whole seconds:"
+ Math.floor(process.uptime())
+ " seconds");
}
輸出:
the number of seconds the Node.js process is running:0.077 seconds the number of seconds the Node.js process is running:0.087 seconds In whole seconds:0 seconds
注意:上麵的程序將通過使用node filename.js
命令。
參考: https://nodejs.org/api/process.html#process_process_uptime
相關用法
- Node.js GM drawRectangle()用法及代碼示例
- Node.js GM minify()用法及代碼示例
- Node.js GM magnify()用法及代碼示例
- Node.js GM whiteThreshold()用法及代碼示例
- Node.js GM whitePoint()用法及代碼示例
- Node.js GM write()用法及代碼示例
- Node.js GM drawBezier()用法及代碼示例
- Node.js GM drawPolyline()用法及代碼示例
- Node.js GM drawArc()用法及代碼示例
- Node.js GM drawLine()用法及代碼示例
注:本文由純淨天空篩選整理自gekcho大神的英文原創作品 Node.js | process.uptime() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。