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/

相关文章:

matlab - 如果未分配变量,则忽略所有输出参数

c - 如何使用 fork() 创建一定数量的子进程

c - 从 pthread 运行 pthreads

linux - 如何从 Linux 内核调用标准库?

linux - 以 systemd 启动的进程正在记录到/var/log/syslog 和/var/log/daemon.log

c++ - setsockopt 正在尝试将 IGMP 数据包发送到接口(interface)关闭

c++ - 为什么这个代码片段用 VS2010 编译而不用 GCC 4.5.2?

javascript - 为什么当我调用有返回值的函数时,我的 onclick 事件不起作用?

c - 在第一个线程完成之前,第二个线程不会运行

c - pthread_create 错误