时间 = 本地时间 - 时区差).
构造函数:
1. 通过当前时间构造
2. 通过Timestamp对象
3. 通过年、月、日、时、分、秒、微秒、毫秒构造
4. 通过儒略日时间构造(儒略日时间用double存储)
5. 作为可选项。时区可作为构造时第一个参数被指定。(如果没有指定的话,会使用系统当前的时区)
成员函数:
1. LocalDateTime支持所有的DateTime的函数。
2. 在进行比较之前,所有的关系操作符函数会把时间都换算为UTC时间
3. int tzd() const
返回时区差
4. DateTime utc() const
转换本地时间到utc时间
下面是一个例子:
[cpp]
#include "Poco/LocalDateTime.h"
using Poco::LocalDateTime;
int main(int argc, char** argv)
{
LocalDateTime now; // the current date and local time
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();
int tzd = now.tzd();
double jd = now.julianDay();
Poco::Timestamp ts = now.timestamp();
LocalDateTime dt1(1973, 9, 12, 2, 30, 45); // 1973-09-12 02:30:45
dt1.assign(2006, 10, 13, 13, 45, 12, 345); // 2006-10-13 12:45:12.345
LocalDateTime dt2(3600, 1973, 9, 12, 2, 30, 45, 0, 0); // UTC +1 hour
dt2.assign(3600, 2006, 10, 13, 13, 45, 12, 345, 0);
Poco::Timestamp nowTS;
LocalDateTime dt3(3600, nowTS); // construct from Timestamp
return 0;
}
#include "Poco/LocalDateTime.h"
using Poco::LocalDateTime;
int main(int argc, char** argv)
{
LocalDateTime now; // the current date and local time
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();
int tzd = now.tzd();
double jd = now.julianDay();
Poco::Timestamp ts = now.timestamp();
LocalDateTime dt1(1973, 9, 12, 2, 30, 45); // 1973-09-12 02:30:45
dt1.assign(2006, 10, 13, 13, 45, 12, 345); // 2006-10-13 12:45:12.345
LocalDateTime dt2(3600, 1973, 9, 12, 2, 30, 45, 0, 0); // UTC +1 hour
dt2.assign(3600, 2006, 10, 13, 13, 45, 12, 345, 0);
Poco::Timestamp nowTS;
LocalDateTime dt3(3600, nowTS); // construct from Timestamp
return 0;
}
5. Timespan类
Poco::Timespan能够提供一个微秒精度的时间间隔,也可以用天、小时、分钟、秒、微秒、毫秒来表示。在其内部这个时间间隔用一个64-bit整形来表示。
构造函数:
1. 一个TimeStamp::TimeDiff对象(微秒精度)
2. 秒+微秒
主要用于从timeva l结构体构建
3. 通过日、时、分、秒、微秒构造
操作符:
1. Poco::Timespan支持所有的关系操作符
(==, !=, <, <=, >, >=)
2. Poco::Timespan支持加法和减法操作
(+, -, +=, -=)
成员函数:
1. int days() const
返回时间跨度的天
2. int hours() const
返回时间跨度的小时(0 - 23)
3. int totalHours() const
返回时间跨度总的小时数
4. int minutes() const
返回时间跨度的分钟(0 - 59)
5. int totalMinutes() const
返回时间跨度总的分钟数
6. int seconds() const
返回时间跨度的秒(0 - 60)
7. int totalSeconds() const
返回时间跨度总的秒数
8. int milliseconds() const
返回时间跨度的毫秒((0 - 999)
9. int totalMilliseconds() const
返回时间跨度总的毫秒数
10. int microseconds() const
返回时间跨度的微秒( (0 - 999)
11. int totalMicroseconds() const
返回时间跨度总的微秒数
下面是一个例子:
[cpp]
#include "Poco/Timespan.h"
using Poco::Timespan;
int main(int argc, char** argv)
{
Tim