node.js 获取日期
All the file functions in Node.js are provided by the fs
module. This module exposes a method called statSync()
, which gets the file details synchronously.
Node.js中的所有文件功能均由fs
模块提供。 该模块公开了一个名为statSync()
的方法,该方法同步获取文件详细信息。
By calling it passing a file path (relative to the file location, or absolute), it will return an object that contains the mtime
property.
通过调用它传递文件路径(相对于文件位置或绝对路径),它将返回包含mtime
属性的对象。
That is a Date
object instance that contains the file last modified date.
这是一个Date
对象实例,其中包含文件的上次修改日期。
const fs = require('fs')
const getFileUpdatedDate = (path) => {
const stats = fs.statSync(path)
return stats.mtime
}
Check out the JavaScript Date guide to find out more how to handle the Date object, if you need.
如果需要,请查看JavaScript日期指南,以了解更多有关如何处理Date对象的信息。
翻译自: https://flaviocopes.com/how-to-get-last-updated-date-file-node/
node.js 获取日期