POCO C++库学习和分析-- 日期与时间(4)
11. int days = age.days(); // in days
12. int hours = age.totalHours(); // in hours 13. int secs = age.totalSeconds(); // in seconds 14. // when was I 10000 days old? 15. Timespan span(10000*Timespan::DAYS); 16. DateTime dt = birthdate + span; 17. return 0; 18. }
6. Timezone类
Poco::Timezone提供静态函数用于获取时区信息和夏令时信息。 1. 时区差
2. 是否采用夏时制(daylight saving time (DST)) 3. 时区名
成员函数:
1. int utcOffset()
返回本地时间相对于UTC时间的差值(精度秒)。不包括夏令时偏移: (local time = UTC + utcOffset()) 2. int dst()
返回夏令时偏移。通常是固定值3600秒。0的话表示无夏令时。 3. bool isDst(const Timestamp& timestamp)
对于给定的timestamp时间测试,是否使用夏令时 4. int tzd()
返回本地时间相对于UTC时间的差值(精度秒)。包括夏令时偏移: (tzd = utcOffset() + dst()) 5. std::string name() 返回当前的时区名
6. std::string standardName()
返回当前的标准时区名(如果不采用夏令时) 7. std::string dstName()
返回当前的时区名(如果采用夏令时)
8. 时区名的返回依赖于操作系统,并且名称不具有移植性,仅作显示用。
下面是一个使用的例子:
[cpp] view plaincopy
1. #include \ 2. #include \ 3. using Poco::Timezone; 4. using Poco::Timestamp;
5. int main(int argc, char** argv) 6. {
7. int utcOffset = Timezone::utcOffset(); 8. int dst = Timezone::dst();
9. bool isDst = Timezone::isDst(Timestamp()); 10. int tzd = Timezone::tzd();
11. std::string name = Timezone::name();
12. std::string stdName = Timezone::standardName(); 13. std::string dstName = Timezone::dstName(); 14. return 0; 15. }
6. Poco::DateTimeFormatter类
Poco::DateTimeFormatter用来定义当Timestamp, DateTime, LocalDateTime and Timespan转换为字符串时所需的日期和事件格式。Poco::DateTimeFormatter的作用和strftime()是类似的。Poco::DateTimeFormat内部定义了一些约定的格式。
1. ISO8601_FORMAT (2005-01-01T12:00:00+01:00) 2. RFC1123_FORMAT (Sat, 1 Jan 2005 12:00:00 +0100) 3. SORTABLE_FORMAT (2005-01-01 12:00:00)
4. For more information, please see the reference documentation.
成员函数:
所有的DateTimeFormatter函数都是静态的。
下面是一个使用的例子:
[cpp] view plaincopy
1. #include \ 2. #include \
3. #include \ 4. #include \ 5. using Poco::DateTimeFormatter; 6. using Poco::DateTimeFormat; 7. int main(int argc, char** argv) 8. {
9. Poco::DateTime dt(2006, 10, 22, 15, 22, 34);
10. std::string s(DateTimeFormatter::format(dt, \)); 11. // \ 12. Poco::Timestamp now;
13. s = DateTimeFormatter::format(now, DateTimeFormat::SORTABLE_FORMAT); 14. // \
15. Poco::Timespan span(5, 11, 33, 0, 0);
16. s = DateTimeFormatter::format(span, \); 17. // \ 18. return 0; 19. }
7. Poco::DateTimeParser类
Poco::DateTimeParser用来从字符串中解析时间和日期。下面是其一个例子:
[cpp] view plaincopy
1. #include \ 2. #include \ 3. #include \ 4. #include \ 5. #include \ 6. using Poco::DateTimeParser; 7. using Poco::DateTimeFormat; 8. using Poco::DateTime;
9. int main(int argc, char** argv) 10. {
11. std::string s(\); 12. int tzd; 13. DateTime dt;
14. DateTimeParser::parse(DateTimeFormat::RFC1123_FORMAT, s, dt, tzd); 15. Poco::Timestamp ts = dt.timestamp(); 16. Poco::LocalDateTime ldt(tzd, dt);
17. bool ok = DateTimeParser::tryParse(\, dt, tzd); 18. ok = DateTimeParser::tryParse(\, \, dt, tzd); 19. return 0; 20. }
8. Stopwatch类
Stopwatch用来测量时间差值,精度为微秒.下面是其定义:
[cpp] view plaincopy
1. class Foundation_API Stopwatch
2. /// A simple facility to measure time intervals 3. /// with microsecond resolution. 4. ///
5. /// Note that Stopwatch is based on the Timestamp 6. /// class. Therefore, if during a Stopwatch run, 7. /// the system time is changed, the measured time 8. /// will not be correct. 9. { 10. public:
11. Stopwatch(); 12. ~Stopwatch();
13. 14.
15. void start();
16. /// Starts (or restarts) the stopwatch. 17.
18. void stop();
19. /// Stops or pauses the stopwatch. 20.
21. void reset();
22. /// Resets the stopwatch. 23.
24. void restart();
25. /// Resets and starts the stopwatch. 26.
27. Timestamp::TimeDiff elapsed() const;
28. /// Returns the elapsed time in microseconds 29. /// since the stopwatch started. 30.
31. int elapsedSeconds() const;
32. /// Returns the number of seconds elapsed 33. /// since the stopwatch started. 34. 35.
36. static Timestamp::TimeVal resolution();
37. /// Returns the resolution of the stopwatch. 38. 39.
40. private:
41. Stopwatch(const Stopwatch&);
42. Stopwatch& operator = (const Stopwatch&); 43. 44.
45. Timestamp _start; 46. Timestamp::TimeDiff _elapsed; 47. bool _running; 48. };
附录:
1. The Gregorian Calendar: http://en.wikipedia.org/wiki/Gregorian_calend …… 此处隐藏:2116字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [综合文档]应答器设备技术规范(征求意见稿)A1
- [综合文档]教师 2012年高考政治试题按考点分类汇
- [综合文档]保险公司的总经理助理竞职演说
- [综合文档]卫生应急大练兵大比武活动考试--题库(
- [综合文档]徐州经济技术开发区总体规划环境影响报
- [综合文档]汉语拼音表(带声调)
- [综合文档]二年级 上 思维训练( 1~18)
- [综合文档]特色学校五年发展规划
- [综合文档]机床经常出现报警“X1轴定位监控”
- [综合文档]《电子技术基础》21.§5—2、3、4 习题
- [综合文档]浙江省深化普通高中课程改革
- [综合文档]CRISP原理 - 图文
- [综合文档]2017年电大社会调查研究与方法形考答案
- [综合文档]浅析建筑施工安全毕业论文
- [综合文档]《回忆我的母亲》名师教案
- [综合文档]装饰装修工程监理规划
- [综合文档]三下乡心得体会-文艺
- [综合文档]柱计算长度系数 - 图文
- [综合文档]全流程思考,提高燃电系统热电转换率--
- [综合文档]2018年嘉定区中考物理一模含答案
- 433M车库门滚动码遥控器
- 8、架空线路施工规范
- 大学四年声乐学习的体会
- 新北师大版五年级数学上册《轴对称再认
- 部编版五年级上册语文第六单元小结复习
- 小学六年级英语形容词用法
- 第2课 抗美援朝保家卫国 课件01(岳麓版
- 2015年天津大学运筹学基础考研真题,考
- 微机计算机控制技术课后于海生(第2版)
- 安全教育实践活动
- Delphi程序设计教程_第1章_Delphi概述
- 第八讲 工业革命与启蒙运动
- 《中华人民共和国药典》2005年版二部勘
- 科粤版九年级化学2.3构成物质的微粒(1)
- 西师大版数学三年级下册《长方形、正方
- ch6_冒泡排序演示
- 第4章 冲裁模具设计
- 浙江中小民营企业员工流失论文[终稿]
- 再议有线数字电视市场营运模式
- 昆明供水工程监理大纲




