POCO C++库学习和分析-- 日期与时间(3)
儒略日和儒略日日期
儒略日的起点订在公元前4713年(天文学上记为 -4712年)1月1日格林威治时间平午(世界时12:00),即JD 0指定为UT时间B.C.4713年1月1日12:00到UC时间B.C.4713年1月2日12:00的24小时。注意这一天是礼拜一。每一天赋予了一个唯一的数字,顺数而下,如:1996年1月1日12:00:00的儒略日是2450084。这个日期是考虑了太阳、月亮的轨道运行周期,以及当时收税的间隔而订出来的。Joseph Scliger定义儒略周期为7980年,是因28、19、15的最小公倍数为28×19×15=7980。
日期的注意事项:
1. 0是一个合法数字(根据ISO 8691和天文年编号) 2. 0年是一个闰年。
3. 负数是不支持的。比如说公元前1年。
4. 格里高利历同历史上的日期可能不同,由于它们采用的日历方式不同。 5. 最好只是用DateTime用来计算当前的时间。对于历史上的或者天文日历的时间计算,还是使用其他的特定软件。
构造DateTime:
1. 可以从一个已有的DateTime构造 2. 当前的时间和日期 3. 一个Timestamp对象
4. 用年、月、日、时、分、秒、微秒、毫秒构造 5. 使用一个儒略日日期构造(用double形式保存)
成员函数:
1. int year() const 返回年
2. int month() const 返回月(1-12)
3. int week(int firstDayOfWeek = DateTime::MONDAY) const
返回所在的周,根据ISO 8601标准(第一周是1月4日所在的周),一周的第一天是礼拜一或者礼拜天。
4. int day() const
返回月中的所在天(1 - 31) 5. int dayOfWeek() const
返回周中的所在天 0为周日,1为周一,..... 6. int dayOfYear() const
返回年中的所在天(1 - 366) 7. int hour() const
返回天中所在小时(0 - 23) 8. int hourAMPM() const
返回上下午所在小时(0 - 12) 9. bool isAM() const 如果上午返回真 10. bool isPM() const 如果下午返回真 11. int minute() const 返回分钟数(0 - 59) 12. int second() const 返回秒数(0 - 59)
13. int millisecond() const 返回毫秒数(0 - 999)
14. int microsecond() const 返回微秒数(0 - 999)
15. Timestamp timestamp() const
返回用Timestamp保存的日历时间(精度微秒) 16. Timestamp::UtcTimeVal utcTime() const
返回用Timestamp保存的日历时间(精度100纳秒) 17. DateTime支持关系运算符(==, !=, >, >=, <, <=). 18. DateTime支持算术操作(+, -, +=, -=)
静态函数:
1. bool isLeapYear(int year) 所给年是否闰年
2. int daysOfMonth(int year, int month) 所给年和月的天数
3. bool isValid(int year, int month, int day, int hour, int minute, int second, int millisecond, int microsecond)
判断所给年月日是否合法
下面是DateTime的一个例子:
[cpp] view plaincopy
1. #include \ 2. using Poco::DateTime;
3. int main(int argc, char** argv) 4. {
5. DateTime now; // the current date and time in UTC 6. int year = now.year(); 7. int month = now.month(); 8. int day = now.day(); 9. int dow = now.dayOfWeek(); 10. int doy = now.dayOfYear(); 11. int hour = now.hour(); 12. int hour12 = now.hourAMPM(); 13. int min = now.minute(); 14. int sec = now.second(); 15. int ms = now.millisecond(); 16. int us = now.microsecond(); 17. double jd = now.julianDay();
18. Poco::Timestamp ts = now.timestamp();
19. DateTime xmas(2006, 12, 25); // 2006-12-25 00:00:00 20. Poco::Timespan timeToXmas = xmas - now; 21. 22.
23. DateTime dt(1973, 9, 12, 2, 30, 45); // 1973-09-12 02:30:45
24. dt.assign(2006, 10, 13, 13, 45, 12, 345); // 2006-10-13 12:45:12.345 25. bool isAM = dt.isAM(); // false
26. bool isPM = dt.isPM(); // true
27. bool isLeap = DateTime::isLeapYear(2006); // false 28. int days = DateTime::daysOfMonth(2006, 2); // 28
29. bool isValid = DateTime::isValid(2006, 02, 29); // false 30. dt.assign(2006, DateTime::OCTOBER, 22); // 2006-10-22 00:00:00 31. if (dt.dayOfWeek() == DateTime::SUNDAY) 32. {
33. // ... 34. }
35. return 0; 36. }
4. LocalDateTime类
Poco::LocalDateTime同Poco::DateTime类似,不同的是Poco::LocalDateTime存储一个本地时间。关于本地时间和UTC时间有如下计算公式: (UTC时间 = 本地时间 - 时区差).
构造函数:
1. 通过当前时间构造 2. 通过Timestamp对象
3. 通过年、月、日、时、分、秒、微秒、毫秒构造 4. 通过儒略日时间构造(儒略日时间用double存储)
5. 作为可选项。时区可作为构造时第一个参数被指定。(如果没有指定的话,会使用系统当前的时区)
成员函数:
1. LocalDateTime支持所有的DateTime的函数。
2. 在进行比较之前,所有的关系操作符函数会把时间都换算为UTC时间 3. int tzd() const 返回时区差
4. DateTime utc() const 转换本地时间到utc时间
下面是一个例子:
[cpp] view plaincopy
1. #include \ 2. using Poco::LocalDateTime; 3. int main(int argc, char** argv) 4. {
5. LocalDateTime now; // the current date and local time 6. int year = now.year(); 7. int month = now.month(); 8. int day = now.day(); 9. int dow = now.dayOfWeek(); 10. int doy = now.dayOfYear();
11. int hour = now.hour(); 12. int hour12 = now.hourAMPM(); 13. int min = now.minute(); 14. int sec = now.second(); 15. int ms = now.millisecond(); 16. int us = now.microsecond(); 17. int tzd = now.tzd();
18. double jd = now.julianDay();
19. Poco::Timestamp ts = now.timestamp(); 20. 21.
相关推荐:
- [综合文档]应答器设备技术规范(征求意见稿)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章 冲裁模具设计
- 浙江中小民营企业员工流失论文[终稿]
- 再议有线数字电视市场营运模式
- 昆明供水工程监理大纲




