设为首页 加入收藏

TOP

POCO C++库学习和分析 -- 日期与时间 (十)
2014-11-24 03:20:57 】 浏览:1158
Tags:POCO 学习 分析 --日期 时间
espan ts1(1, 11, 45, 22, 123433); // 1d 11h 45m 22.123433s
Timespan ts2(33*Timespan::SECONDS); // 33s
Timespan ts3(2*Timespan::DAYS + 33*Timespan::HOURS); // 3d 33h
int days = ts1.days(); // 1
int hours = ts1.hours(); // 11
int totalHours = ts1.totalHours(); // 35
int minutes = ts1.minutes(); // 45
int totalMins = ts1.totalMinutes(); // 2145
int seconds = ts1.seconds(); // 22
int totalSecs = ts1.totalSeconds(); // 128722
return 0;
}

#include "Poco/Timespan.h"
using Poco::Timespan;
int main(int argc, char** argv)
{
Timespan ts1(1, 11, 45, 22, 123433); // 1d 11h 45m 22.123433s
Timespan ts2(33*Timespan::SECONDS); // 33s
Timespan ts3(2*Timespan::DAYS + 33*Timespan::HOURS); // 3d 33h
int days = ts1.days(); // 1
int hours = ts1.hours(); // 11
int totalHours = ts1.totalHours(); // 35
int minutes = ts1.minutes(); // 45
int totalMins = ts1.totalMinutes(); // 2145
int seconds = ts1.seconds(); // 22
int totalSecs = ts1.totalSeconds(); // 128722
return 0;
}
下面来看一个DateTime, LocalDateTime和Timespan的混合例子:
[cpp]
#include "Poco/DateTime.h"
#include "Poco/Timespan.h"
using Poco::DateTime;
using Poco::Timespan;
int main(int argc, char** argv)
{
// what is my age
DateTime birthdate(1973, 9, 12, 2, 30); // 1973-09-12 02:30:00
DateTime now;
Timespan age = now - birthdate;
int days = age.days(); // in days
int hours = age.totalHours(); // in hours
int secs = age.totalSeconds(); // in seconds
// when was I 10000 days old
Timespan span(10000*Timespan::DAYS);
DateTime dt = birthdate + span;
return 0;
}

#include "Poco/DateTime.h"
#include "Poco/Timespan.h"
using Poco::DateTime;
using Poco::Timespan;
int main(int argc, char** argv)
{
// what is my age
DateTime birthdate(1973, 9, 12, 2, 30); // 1973-09-12 02:30:00
DateTime now;
Timespan age = now - birthdate;
int days = age.days(); // in days
int hours = age.totalHours(); // in hours
int secs = age.totalSeconds(); // in seconds
// when was I 10000 days old
Timespan span(10000*Timespan::DAYS);
DateTime dt = birthdate + span;
return 0;
}


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]
#include "Poco/Timezone.h"
#include "Poco/Timestamp.h"
using Poco::Timezone;
using Poco::Timestamp;
int main(int argc, char** argv)
{
int utcOffset = Timezone::utcOffset();
int dst = Timezone::dst();
bool isDst = Timezone::isDst(Timestamp());
int tzd = Timezone::tzd();
std::string name = Timezone::name();
std::string stdName = Timezone::standardName();
std::string dstName = Timezone::dstName();
return 0;
}

#include "Poco/Timezone.h"
#include "Poco/Timestamp.h"
usin

首页 上一页 7 8 9 10 11 12 下一页 尾页 10/12/12
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇fzu 2035 Axial symmetry(几何) 下一篇BZOJ 2565 最长双回文串

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目