我正在尝试使用以下代码找到两个日期之间的区别(即14:49:41和15:50:42):
Action()
{
struct tm {
int tm_sec;
int tm_min;
int tm_hour;
};
int rc; // return code
struct tm date1;
struct tm date2;
long time_difference; // the number of time ticks (seconds) that separate date1 and date2.
int hours, minutes, seconds;
// Save example dates to a parameter.
// capture these values using web_reg_save_param or similar.
// date format: hh:mm:ss
lr_save_string("14:49:41", "Param_Date1");
lr_save_string("15:50:42", "Param_Date2");
// Read the values from the string into the date variables
rc = sscanf(lr_eval_string("{Param_Date1}"), "%d:%d:%d",&date1.tm_hour, &date1.tm_min, &date1.tm_sec);
// Repeat the above steps for Date2
rc = sscanf(lr_eval_string("{Param_Date2}"), "%d:%d:%d", &date2.tm_hour, &date2.tm_min, &date2.tm_sec);
time_difference = mktime(&date2) - mktime(&date1);
lr_output_message("Total number of seconds difference: %d", time_difference);
// Calculate time difference in hours, minutes and seconds.
hours = time_difference/3600;
time_difference = time_difference - (hours * 3600);
minutes = time_difference/60;
time_difference = time_difference - (minutes * 60);
seconds = time_difference;
lr_output_message("Hours: %d, Minutes: %d, Seconds: %d", hours, minutes, seconds);
return 0;
}
实际输出应返回:小时:1,分钟:1,秒:1
但是输出返回:小时:0,分钟:0,秒:0
请帮助我解决此问题。还是其他任何替代方法可以实现?
最佳答案
将值除以3600时,不应将小时,分钟和秒声明为整数。如果将它们声明为浮点数,则可能会起作用。除此之外,一切看起来都不错
关于c - 如何用C语言-Loadrunner Web区分两个日期时间?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50858667/