您好,我想知道是否可以编辑时间函数。让我的程序为用户重新尝试提供时间?
struct tm * abc()
{
char *time_string;
time_t curtime;
struct tm *loctime;
/* Get the current time. */
curtime = time (NULL);
/* Convert it to local time representation. */
loctime = localtime (&curtime);
return loctime;
}
这将返回当前时间,但我想做的是编辑它以添加一个值。我这样做的原因是我可以告诉用户在某个时间使用当前的时间再试一次,并向其添加 2 分钟。不确定这是否是正确的方法? 谢谢
最佳答案
time() 返回以秒为单位的时间戳(自 the epoch 以来的秒数),因此您只需添加所需的延迟即可。
curtime = time (NULL) + 2*60; // Adds two minutes,
关于c - C linux中的时间函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5234942/