gpt4 book ai didi

c - C语言-Loadrunner Web中如何区分两个日期时间?

转载 作者:行者123 更新时间:2023-11-30 16:30:54 26 4
gpt4 key购买 nike

我试图使用以下代码查找两个日期(即 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。如果您将它们声明为 float ,则可能会起作用。除此之外一切看起来都不错

关于c - C语言-Loadrunner Web中如何区分两个日期时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50858667/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com