c - C linux中的时间函数

标签 c linux function time

您好,我想知道是否可以编辑时间函数。让我的程序为用户重新尝试提供时间?

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/

相关文章:

c - 确定两个字符串是否为字谜?

c - 打印垂直直方图

c++ - 最快的仪器分析器是什么

linux - grep 不匹配模式与 html 文件中的空格

function - 可以在 matlab 类中重载函数吗?

phpeclipse : jump to function definition?

c - 一次在多维数组中写入一个字符串 C

c - 在 C 中使用 msgpack 接收流

linux - 更新 header 中的 TCP/IP 校验和

c - 我可以使用带有返回值的if语句作为C中的函数参数吗?