POCO C++库学习和分析 -- 日期与时间 (十二)

2014-11-24 03:20:57 · 作者: · 浏览: 7
, s, dt, tzd);
Poco::Timestamp ts = dt.timestamp();
Poco::LocalDateTime ldt(tzd, dt);
bool ok = DateTimeParser::tryParse("2006-10-22", dt, tzd);
ok = DateTimeParser::tryParse("%e.%n.%Y", "22.10.2006", dt, tzd);
return 0;
}


8. Stopwatch类
Stopwatch用来测量时间差值,精度为微秒.下面是其定义:
[cpp]
class Foundation_API Stopwatch
/// A simple facility to measure time intervals
/// with microsecond resolution.
///
/// Note that Stopwatch is based on the Timestamp
/// class. Therefore, if during a Stopwatch run,
/// the system time is changed, the measured time
/// will not be correct.
{
public:
Stopwatch();
~Stopwatch();


void start();
/// Starts (or restarts) the stopwatch.

void stop();
/// Stops or pauses the stopwatch.

void reset();
/// Resets the stopwatch.

void restart();
/// Resets and starts the stopwatch.

Timestamp::TimeDiff elapsed() const;
/// Returns the elapsed time in microseconds
/// since the stopwatch started.

int elapsedSeconds() const;
/// Returns the number of seconds elapsed
/// since the stopwatch started.


static Timestamp::Timeva l resolution();
/// Returns the resolution of the stopwatch.


private:
Stopwatch(const Stopwatch&);
Stopwatch& operator = (const Stopwatch&);


Timestamp _start;
Timestamp::TimeDiff _elapsed;
bool _running;
};

class Foundation_API Stopwatch
/// A simple facility to measure time intervals
/// with microsecond resolution.
///
/// Note that Stopwatch is based on the Timestamp
/// class. Therefore, if during a Stopwatch run,
/// the system time is changed, the measured time
/// will not be correct.
{
public:
Stopwatch();
~Stopwatch();


void start();
/// Starts (or restarts) the stopwatch.

void stop();
/// Stops or pauses the stopwatch.

void reset();
/// Resets the stopwatch.

void restart();
/// Resets and starts the stopwatch.

Timestamp::TimeDiff elapsed() const;
/// Returns the elapsed time in microseconds
/// since the stopwatch started.

int elapsedSeconds() const;
/// Returns the number of seconds elapsed
/// since the stopwatch started.


static Timestamp::Timeva l resolution();
/// Returns the resolution of the stopwatch.


private:
Stopwatch(const Stopwatch&);
Stopwatch& operator = (const Stopwatch&);


Timestamp _start;
Timestamp::TimeDiff _elapsed;
bool _running;
};