st
返回年中的所在天(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::UtcTimeva l 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]
#include "Poco/DateTime.h"
using Poco::DateTime;
int main(int argc, char** argv)
{
DateTime now; // the current date and time in UTC
int year = now.year();
int month = now.month();
int day = now.day();
int dow = now.dayOfWeek();
int doy = now.dayOfYear();
int hour = now.hour();
int hour12 = now.hourAMPM();
int min = now.minute();
int sec = now.second();
int ms = now.millisecond();
int us = now.microsecond();
double jd = now.julianDay();
Poco::Timestamp ts = now.timestamp();
DateTime xmas(2006, 12, 25); // 2006-12-25 00:00:00
Poco::Timespan timeToXmas = xmas - now;
DateTime dt(1973, 9, 12, 2, 30, 45); // 1973-09-12 02:30:45
dt.assign(2006, 10, 13, 13, 45, 12, 345); // 2006-10-13 12:45:12.345
bool isAM = dt.isAM(); // false
bool isPM = dt.isPM(); // true
bool isLeap = DateTime::isLeapYear(2006); // false
int days = DateTime::daysOfMonth(2006, 2); // 28
bool isValid = DateTime::isValid(2006, 02, 29); // false
dt.assign(2006, DateTime::OCTOBER, 22); // 2006-10-22 00:00:00
if (dt.dayOfWeek() == DateTime::SUNDAY)
{
// ...
}
return 0;
}
#include "Poco/DateTime.h"
using Poco::DateTime;
int main(int argc, char** argv)
{
DateTime now; // the current date and time in UTC
int year = now.year();
int month = now.month();
int day = now.day();
int dow = now.dayOfWeek();
int doy = now.dayOfYear();
int hour = now.hour();
int hour12 = now.hourAMPM();
int min = now.minute();
int sec = now.second();
int ms = now.millisecond();
int us = now.microsecond();
double jd = now.julianDay();
Poco::Timestamp ts = now.timestamp();
DateTime xmas(2006, 12, 25); // 2006-12-25 00:00:00
Poco::Timespan timeToXmas = xmas - now;
DateTime dt(1973, 9, 12, 2, 30, 45); // 1973-09-12 02:30:45
dt.assign(2006, 10, 13, 13, 45, 12, 345); // 2006-10-13 12:45:12.345
bool isAM = dt.isAM(); // false
bool isPM = dt.isPM(); // true
bool isLeap = DateTime::isLeapYear(2006); // false
int days = DateTime::daysOfMonth(2006, 2); // 28
bool isValid = DateTime::isValid(2006, 02, 29); // false
dt.assign(2006, DateTime::OCTOBER, 22); // 2006-10-22 00:00:00
if (dt.dayOfWeek() == DateTime::SUNDAY)
{
// ...
}
return 0;
}
4. LocalDateTime类
Poco::LocalDateTime同Poco::DateTime类似,不同的是Poco::LocalDateTime存储一个本地时间。关于本地时间和UTC时间有如下计算公式:
(UTC