function init() {
var sendDate = (new Date()).Format( "yyyy-MM-dd hh:mm:ss" );
var returnDate = (new Date()).Format( "yyyy-MM-dd hh:mm:ss" );
try {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var parentPath = "f:\\SILOG" ;
var childPath = parentPath + "\\" + ( new Date()).Format("yyyy-MM-dd");
var fname = childPath + "\\" + "SILOG.log";
if(!fso.FolderExists(parentPath)) {
fso.CreateFolder(parentPath);
}
if(!fso.FolderExists(childPath)) {
fso.CreateFolder(childPath);
}
var logStr = "交易:" +" 发送请求时间:" + sendDate+ " 获取返回值时间:"+ returnDate+
"\r\n" + "入参:" + "\r\n" + "发送内容" +
"\r\n" + "出参:" + "\r\n" + "返回内容" ;
var logFile= fso.OpenTextFile(fname,8,true,0);
logFile.WriteLine(logStr);
logFile.close();
} catch(ex) {
//避免影响正常业务进行,异常不进行处理
}
}
Date.prototype.Format = function (fmt) {
var o = {
"M+": this.getMonth() + 1, //月份
"d+": this.getDate(), //日
"h+": this.getHours(), //小时
"m+": this.getMinutes(), //分
"s+": this.getSeconds(), //秒
"q+": Math.floor((this.getMonth() + 3) / 3), //季度
"S": this.getMilliseconds() //毫秒
};
if (/(y+)/ .test(fmt)) fmt = fmt.replace(RegExp.$1, (this .getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
详解:
Date.prototype.Format方法为格式化前台时间:
(new Date()).Format( "yyyy-MM-dd hh:mm:ss" )
创建FileSystemObject对象:
var fso = new ActiveXObject("Scripting.FileSystemObject");
打开指定的文件并返回一个 TextStream 对象,可以读取、写入此对象或将其追加到文件:
fso.OpenTextFile(fname,8,true);
object.OpenTextFile(filename[, iomode[, create[, format]]])
参数
object:必选项。应为 FileSystemObject 对象的名称。
filename:必选项。字符串表达式,指明要打开的文件名称
iomode:可选项。输入/输出模式,是下列三个常数之一:ForReading,ForWriting或 ForAppending
create:可选项。Boolean 值,指出当指定的 filename 不存在时是否能够创建新文件。允许创建新文件时为 True,否则为 False。默认值为 False
format:可选项。三个 Tristate 值之一,指出以何种格式打开文件。若忽略此参数,则文件以 ASCII 格式打开