文件属性的时间值


atimeMsmtimeMsctimeMs 以及 birthtimeMs 属性是是保存相应时间(以毫秒为单位)的数字。 它们的精确度取决于平台。 atimemtimectime 以及 birthtime 是对应时间的 Date 对象。 Date 值和数字值没有关联性。 对数字值重新赋值、或者改变 Date 值,都不会影响到对应的属性。

stat 对象中的时间具有以下语义:

  • atime "访问时间" - 上次访问文件数据的时间。由 mknod(2)utimes(2)read(2) 系统调用更改。
  • mtime "修改时间" - 上次修改文件数据的时间。由 mknod(2)utimes(2)write(2) 系统调用更改。
  • ctime "变化时间" - 上次更改文件状态的时间(修改索引节点数据)。由 chmod(2)chown(2)link(2)mknod(2)rename(2)unlink(2)utimes(2)read(2)write(2) 系统调用更改。
  • birthtime "创建时间" - 文件创建的时间。 创建文件时设置一次。 在不支持创建时间的文件系统上,该字段可能被替代为 ctime1970-01-01T00:00Z(如 Unix 纪元时间戳 0)。 在这种情况下,该值可能大于 atimemtime。 在 Darwin 和其他的 FreeBSD 衍生系统上,如果使用 utimes(2) 系统调用将 atime 显式地设置为比 birthtime 更早的值,也会有这种情况。

在 Node.js 0.12 之前,ctime 在 Windows 上保存 birthtime。 从 0.12 开始,ctime 不再是“创建时间”,而在 Unix 系统上则一直都不是。

The atimeMs, mtimeMs, ctimeMs, birthtimeMs properties are numbers that hold the corresponding times in milliseconds. Their precision is platform specific. atime, mtime, ctime, and birthtime are Date object alternate representations of the various times. The Date and number values are not connected. Assigning a new number value, or mutating the Date value, will not be reflected in the corresponding alternate representation.

The times in the stat object have the following semantics:

  • atime "Access Time" - Time when file data last accessed. Changed by the mknod(2), utimes(2), and read(2) system calls.
  • mtime "Modified Time" - Time when file data last modified. Changed by the mknod(2), utimes(2), and write(2) system calls.
  • ctime "Change Time" - Time when file status was last changed (inode data modification). Changed by the chmod(2), chown(2), link(2), mknod(2), rename(2), unlink(2), utimes(2), read(2), and write(2) system calls.
  • birthtime "Birth Time" - Time of file creation. Set once when the file is created. On filesystems where birthtime is not available, this field may instead hold either the ctime or 1970-01-01T00:00Z (ie, unix epoch timestamp 0). This value may be greater than atime or mtime in this case. On Darwin and other FreeBSD variants, also set if the atime is explicitly set to an earlier value than the current birthtime using the utimes(2) system call.

Prior to Node.js 0.12, the ctime held the birthtime on Windows systems. As of 0.12, ctime is not "creation time", and on Unix systems, it never was.