Boost庫時間日期學習

2021-06-07 15:09:02 字數 894 閱讀 3699

學習內容見《boost程式庫完全開發指南》第2章 時間與日期

學習三個類的使用timer、progress_timer、date。

boost庫的配置可參照:

開發環境:winxp+vs2005+ boost_1_49_0。

以下所有示例程式均為控制台程式。

1、timer類

timer類是乙個小型的計時器,提供毫秒級別的計時精度。

#include "stdafx.h"

#include #include using namespace std;

using namespace boost;

int _tmain(int argc, _tchar* argv)}}

return 0;

}

3、date類

date類使用32位的整數作為內部儲存,以天為基本單位。使用date日期運算更加方便。

一周前、三月前、一年前日期確定,採用date來計算。

原先演算法見:

#include "stdafx.h"

#include #include using namespace std;

using namespace boost::gregorian;

int _tmain(int argc, _tchar* argv)

{ date d1(2000,1,1);

date d2(2008,8,8);

//輸出相差多少天

cout<<(d2-d1)<

輸出結果如下:

3142

2012-06-23

2012-03-31

2011-06-30

boost 日期與時間相關庫

1.timer類 include stdafx.h include include using namespace std using namespace boost int tmain int argc,tchar argv 2.boost progress timer t類 自動列印輸出流逝的時...

時間日期類

問題及 檔名稱 test.cpp 完成日期 2015年05月27日 版本號 v1.0 定義乙個日期類date,資料成員包括年 月 日,setdate int y,int m,int d 和printdate 函式分別用於設定日期和顯示日期 再定義乙個時間類time,資料成員包括時 分 秒,setti...

時間,日期 datetime time

coding utf 8 1.時間 日期 datetime 日期 import datetime today datetime.datetime.now print today 2.from 模組 import 類 函式 從datetime模組中 引入datetime這個類,這類中有一些函式可以使用...