Yof*_*ine 10 javascript node.js
In nodejs, the arguments of fs.utimes should be written in what format?e.g.atime,mtime.
API: fs.utimes(path, atime, mtime, callback)
Nat*_*son 11
Those parameters are JavaScript Dates, not strings.
Please note that atime, mtime and ctime are instances of Date object and to compare the values of these objects you should use appropriate methods. For most general uses getTime() will return the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC and this integer should be sufficient for any comparison, however there additional methods which can be used for displaying fuzzy information. More details can be found in the MDN JavaScript Reference page.
And from the source code:
fs.utimes = function(path, atime, mtime, callback) {
callback = makeCallback(callback);
if (!nullCheck(path, callback)) return;
binding.utimes(pathModule._makeLong(path),
toUnixTimestamp(atime),
toUnixTimestamp(mtime),
callback);
};
// converts Date or number to a fractional UNIX timestamp
function toUnixTimestamp(time) {
if (util.isNumber(time)) {
return time;
}
if (util.isDate(time)) {
// convert to 123.456 UNIX timestamp
return time.getTime() / 1000;
}
throw new Error('Cannot parse time: ' + time);
}
Run Code Online (Sandbox Code Playgroud)
Which shows that it can be a Javascript Date or Unix Style numeric date.
This line is REALLY important!!! return time.getTime() / 1000; It means that if you pass in a number you pass in a Unix style number where the milliseconds are represented in 1/1000s which is different than the integer returned from Date.getTime()
See this link on Unix Timestamps
| 归档时间: |
|
| 查看次数: |
2475 次 |
| 最近记录: |