代码是这样的,获取某一个文件目录:
getToc: function(dir, callback){
//console.log(dir)
var resJSON = {
queryDir: dir,
folder: [],
document: []
};
fs.readdir(dir, function(err, files){
if(err){
resJSON.err = err;
callback(resJSON);
return;
}
for(var i = 0, len = files.length; i < len; i++){
var pathname = dir + "\/" + files[i];
var stat = fs.lstatSync(pathname);
if (!stat.isDirectory()){
var a = files[i].split('.');
var date = new Date(stat.atime).toLocaleFormat(); //这行报错
resJSON.document.push({type:a[a.length-1],name:files[i],size:stat.size,lastModfied:date});
} else {
resJSON.folder.push(files[i]);
}
}
callback(resJSON);
});
}
错误提示是没有toLocaleFormat方法:TypeError: Object Mon Jan 28 2013 20:20:33 GMT+0800 (CST) has no method ‘toLocaleFormat’ 在客户端下面代码能正确输出时间格式的: 为什么服务端这个方法不存在呢?