专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > C++

关于获取当前UTC时间与某一时间的时间差有关问题

发布时间:2011-06-28 19:58:12 文章来源:www.iduyao.cn 采编人员:星星草
关于获取当前UTC时间与某一时间的时间差问题
假如我现在获取到当前utc时间,如何得到它与今晚12点时间的差值?

求方法

------解决方案--------------------
再获得今晚12点的utc时间,然后相减。
------解决方案--------------------
struct tm ,time_t互相转换就可以了,具体使用参看msdn或百度
------解决方案--------------------
difftime
Finds the difference between two times.

double difftime( time_t timer1, time_t timer0 );

Routine Required Header Compatibility 
difftime <time.h> ANSI, Win 95, Win NT 


For additional compatibility information, see Compatibility in the Introduction.

Libraries

LIBC.LIB Single thread static library, retail version 
LIBCMT.LIB Multithread static library, retail version 
MSVCRT.LIB Import library for MSVCRT.DLL, retail version 


Return Value

difftime returns the elapsed time in seconds, from timer0 to timer1. The value returned is a double-precision floating-point number.

Parameters

timer1

Ending time

timer0

Beginning time

Remarks

The difftime function computes the difference between the two supplied time values timer0 and timer1.

Example 

/* DIFFTIME.C: This program calculates the amount of time
 * needed to do a floating-point multiply 10 million times.
 */

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void main( void )
{
time_t start, finish;
long loop;
double result, elapsed_time;

printf( "Multiplying 2 floating point numbers 10 million times...n" );
 
time( &start );
for( loop = 0; loop < 10000000; loop++ )
result = 3.63 * 5.27; 
time( &finish );

elapsed_time = difftime( finish, start );
printf( "nProgram takes %6.0f seconds.n", elapsed_time );
}


Output

Multiplying 2 floats 10 million times...

Program takes 2 seconds.


Floating-Point Support Routines | Time Management Routines

See Also time

------解决方案--------------------
COleDateTime
COleDateTimeSpan
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: