读书人

unix c的求日期差值的函数解决方案

发布时间: 2012-10-26 10:30:59 作者: rapoo

unix c的求日期差值的函数
谁有现成的求日期差值的函数,??就是跟sybase的datediff一样,
datediff(dd,startdate,enddate);?

[解决办法]
http://blog.csdn.net/xiao__c/article/details/7927669
[解决办法]

C/C++ code
/** * @file        diffdate.c * @brief        */#include <stdio.h>#include <string.h>#include <time.h>double diffdate(const char *date1, const char *date0, const char *fmt){        struct tm tm1, tm0;        memset(&tm1, 0, sizeof(tm1));        memset(&tm0, 0, sizeof(tm0));        strptime(date1, fmt, &tm1);        strptime(date0, fmt, &tm0);        return difftime(mktime(&tm1), mktime(&tm0)) / (3600 * 24);}int main(void){        printf("%f\n", diffdate("2012-03-01 12:00:00", "2012-02-28 00:00:00", "%Y-%m-%d %H:%M:%S"));        return 0;}
[解决办法]
COleDateTimeSpan::GetTotalDays
double GetTotalDays( ) const;

Return Value

This date/time-span value expressed in days. Although this function is prototyped to return a double, it will always return an integer value.

Remarks

Call this member function to retrieve this date/time-span value expressed in days.

The return values from this function range between approximately 3.65e6 and 3.65e6.

For other functions that query the value of a COleDateTimeSpan object, see the following member functions:

GetDays


GetHours


GetMinutes


GetSeconds


GetTotalHours


GetTotalMinutes


GetTotalSeconds
COleDateTimeSpan Overview | Class Members | Hierarchy Chart

See Also COleDateTimeSpan::SetDateTimeSpan, COleDateTimeSpan::operator double

读书人网 >C语言

热点推荐