如何秒添加到当前时间在C? [英] how to add seconds to current time in c?
本文介绍了如何秒添加到当前时间在C?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写在C code和我需要添加由下式给出毫秒当前时间:
I am writing a code in c and I need to add milliseconds to the current time given by :
current_time = time(NULL);
loc_time=localtime(¤t_time);
说的本地时间为20:00:00:10。欲加入10秒,所以它显示20显示出来:00:00:20。我是相当新的C所以任何帮助是非常AP preciated。
我很困惑,时间是INT格式,添加毫秒我会到了0.001秒添加到当前第二这不是一个int。
Say the local time is 20:00:00:10. I want to adding 10 seconds and display it so it displays 20:00:00:20. I am fairly new to c so any help is much appreciated. I am confused as time is in int format and, to add milli seconds I will have to add .001 seconds to the current second which is not an int.
推荐答案
time_t的
只是在几秒钟内一个整数,所以你只需添加10到它:
time_t
is just an integer in seconds, so you simply add 10 to it:
time_wanted = time(NULL) + 10;
loc_time=localtime(&time_wanted);
这篇关于如何秒添加到当前时间在C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文