简体   繁体   English

如何在DevC ++中添加/减去时间

[英]How to Add/Subtract time in DevC++

time (&rawtime); timeinfo = localtime (&rawtime); strftime (buffer,80,"%I:%M:%S",timeinfo);

This is my code to get time. 这是我获取时间的代码。 Just count buffer and it works perfectly fine. 只需计数缓冲区,它就可以正常工作。 I have 2 times (Time Started and Time Finished) and I want to get its process time. 我有2次(Time Started and Time Finished) ,我想获取其处理时间。 Basically its Time2-Time1 formula but I don't know how to do it with this current format. 基本上是它Time2-Time1 formula但我不知道如何使用这种当前格式。 Thanks!! 谢谢!!

If you've got a struct tm , the first thing you'll want to do is convert it into a time_t via mktime() . 如果您有一个struct tm ,您要做的第一件事就是通过mktime()将其转换为time_t。 time_t is more useful for subtraction since it is a simple integer, representing seconds-since-the-epoch-began. time_t对于减法更有用,因为它是一个简单的整数,表示从纪元开始的秒数。 Once you have two time_t values, you can simply subtract one from the other, and the result will the number of seconds between the two times. 一旦有了两个time_t值,就可以简单地从另一个中减去一个,结果将是两次之间的秒数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM