moment().unix()函數用於獲取自Unix紀元以來的秒數。本質上,Unix時間是用於描述時間點的係統。
用法:
moment().unix();
參數:此函數沒有參數。
返回值:此函數以秒為單位返回Unix時間戳。
力矩模塊的安裝:
- 您可以訪問“安裝力矩”模塊的鏈接。您可以使用此命令安裝此軟件包。
npm install moment
- 安裝力矩模塊後,可以使用命令在命令提示符下檢查力矩版本。
npm version moment
- 之後,您可以創建一個文件夾並添加一個文件,例如index.js,如下所示。
範例1: 文件名:index.js
// Requiring the module
const moment = require('moment');
// Function call
var result = moment().unix();
console.log("Result:", result)
運行程序的步驟:
- 項目結構將如下所示:
- 使用以下命令運行index.js文件:
node index.js
輸出:
Result:1595007379
範例2: 文件名:index.js
// Requiring the module
const moment = require('moment');
function getUnixTimeStamp() {
return moment().unix();
}
// Function call
var result = getUnixTimeStamp();
console.log("Unix Timestamp in seconds:", result)
運行程序的步驟:
- 項目結構將如下所示:
- 使用以下命令運行index.js文件:
node index.js
輸出:
Unix Timestamp in seconds:1595007321
相關用法
- PHP Ds\Map get()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- PHP Ds\Map xor()用法及代碼示例
- p5.js mag()用法及代碼示例
- PHP ord()用法及代碼示例
- CSS url()用法及代碼示例
- p5.js value()用法及代碼示例
- PHP Ds\Set add()用法及代碼示例
- p5.js nf()用法及代碼示例
- p5.js nfc()用法及代碼示例
- p5.js nfp()用法及代碼示例
- p5.js nfs()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- p5.js box()用法及代碼示例
- PHP each()用法及代碼示例
- PHP Ds\Set contains()用法及代碼示例
注:本文由純淨天空篩選整理自gouravhammad大神的英文原創作品 Moment.js moment().unix() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。