node.js 获取日期_如何使用Node.js获取文件的最后更新日期

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 获取日期

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值