2009-05-20 74 views
0

我已經給定日期和時間,你如何獲得大紀元時間?

int year, month, day, hour, min, sec 

我怎樣才能獲得在C++中出現時間?

我很難用Boost,任何示例或替代方法來解決這個問題嗎?

+0

你說你試過了。您是否嘗試過http://www.boost.org/doc/libs/1_39_0/doc/html/date_time.html?它帶有例子http://www.boost.org/doc/libs/1_39_0/doc/html/date_time/examples.html – lothar 2009-05-20 21:28:32

回答

4

用你的值填寫struct tm,然後調用std::mktime()

我假設「獲得紀元時間」是指自紀元以來的秒數,即Unix time_t。

+2

這篇文章是完全沒有幫助的,你如何從調用mktime()獲得新紀元時間? – user788171 2012-08-16 01:47:29

1

This boost example應該做你所要求的,如果我確實正確地理解你的問題。

+0

優秀,完美的作品,但你必須下載CSV文件的時區:http://svn.kulitorum.com/RepSnapper/Libraries/Boost1.40/libs/date_time/data/date_time_zonespec.csv – 2012-09-13 14:36:06

1
#include <iostream> 
#include <sys/time.h> 

int main() 
{ 
    unsigned long int seconds = time(NULL); 
    std::cout << seconds << std::endl; 
    return 0; 
}