This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
工具/软件:Code Composer Studio
我们的项目在 Windows 下使用 CSS 版本7.4.0。 我们正在 DSS 下运行用于测试自动化的 JavaScript。 我已经尝试了几种推荐用于 JavaScript 的时间戳方法、但没有找到 DSS 支持的方法。 DSS 似乎不支持所需的函数或 console.log。
是否有人成功地向在 Windows 命令提示符环境中运行 JavaScript 的 DSS 添加了具有毫秒分辨率的时间戳? 如果是、您能否提供您使用的 JavaScript 代码?
您只能使用 JavaScript 日期对象:
https://www.w3schools.com/jsref/jsref_obj_date.asp
我在脚本中执行如下操作:
日期=新日期();
script.traceWrite ("开始时间:"+ date.toTimeString ()+"\n");
Thomas Cox30 说:其中必须记录两个事件之间经过的时间。 这样做的巧妙方法是在每个输出文本行之前、在 DSS 控制台前面加上一个形式为[HH:MM:SS:.mmmh]的时间标签
是的、这是理想的解决方案。 xml 日志中支持该功能,但控制台输出不支持该功能。
[引用用户="Thomas Cox30"]。 换言之,将时间标记机制整合到 traceWrite 和 print 调用中。 如果我要使您的两行示例成为一个函数、我仍然需要在控制台上打印每行文本后找到执行该函数的方法。 [/报价]
是的,您每次在将当前日期/时间打印到控制台之前都要获取该日期/时间
我最终能够创建一个预先挂起到使用 print()函数的控制台输出的时间标记。 我在下面附上了用于 TIMESTAMP.js 的 JavaScript 源代码。
// timestamp.js -为 print()函数的输出添加时间戳前缀。
//时间戳以[13:23:05.380]格式显示。
VAR printLog =打印;
Print =函数(){
var first_parameter =参数[0];
var OTHER 参数= Array.prototype.slice.call(arguments、1);
函数 formatTimeTag (date){
var hour = date.getHours();
var minutes = date.getMinutes();
var 秒= date.getSeconds ();
var 毫秒= date.getMilliseconds ();
返回"['+
((小时< 10)? "0"+小时:小时)+
':'+
((分钟< 10)? "0"+分钟:分钟)+
':'+
((秒< 10)? "0"+秒:秒)+
'。' +
("00"+毫秒).slice (-3)+
']';
}
printLog.appl( print,[formatTimeTag (new Date())+ first_parameter].conomat (Other_parameters));
};