Adbase
Adinf C++ base library V2
adbase::Timestamp Class Reference

时间戳工具类 More...

#include <Timestamp.hpp>

Public Member Functions

 Timestamp ()
 
 Timestamp (int64_t microSecondsSinceEpochArg)
 
void swap (Timestamp &that)
 交换 TimestampMore...
 
std::string toString () const
 Timestamp 转化为字符串 More...
 
std::string toFormattedString (bool showMicroseconds=true) const
 Timestamp 格式化为可视化字符串 More...
 
bool valid () const
 判断 Timestamp 是否合法 More...
 
int64_t microSecondsSinceEpoch () const
 获取 Timestamp 微秒数 More...
 
time_t secondsSinceEpoch () const
 获取 Timestamp 秒数 More...
 

Static Public Member Functions

static Timestamp now ()
 返回当前时间的 Timestamp 对象 More...
 
static Timestamp invalid ()
 
static Timestamp fromUnixTime (time_t t)
 通过 unix time 构建 Timestamp 对象 More...
 
static Timestamp fromUnixTime (time_t t, int microseconds)
 通过 unix time 构建 Timestamp 对象, 并且设置微秒数 More...
 

Static Public Attributes

static const int kMicroSecondsPerSecond = 1000 * 1000
 

Detailed Description

时间戳工具类

Definition at line 20 of file Timestamp.hpp.

Constructor & Destructor Documentation

adbase::Timestamp::Timestamp ( )
inline

Definition at line 22 of file Timestamp.hpp.

Referenced by adbase::addTime(), fromUnixTime(), invalid(), and now().

adbase::Timestamp::Timestamp ( int64_t  microSecondsSinceEpochArg)
inlineexplicit

Definition at line 26 of file Timestamp.hpp.

Member Function Documentation

static Timestamp adbase::Timestamp::fromUnixTime ( time_t  t)
inlinestatic

通过 unix time 构建 Timestamp 对象

Returns
Timestamp 对象

Definition at line 143 of file Timestamp.hpp.

static Timestamp adbase::Timestamp::fromUnixTime ( time_t  t,
int  microseconds 
)
inlinestatic

通过 unix time 构建 Timestamp 对象, 并且设置微秒数

Returns
Timestamp 对象

Definition at line 153 of file Timestamp.hpp.

References kMicroSecondsPerSecond, and Timestamp().

static Timestamp adbase::Timestamp::invalid ( )
inlinestatic

Definition at line 133 of file Timestamp.hpp.

References Timestamp().

int64_t adbase::Timestamp::microSecondsSinceEpoch ( ) const
inline
Timestamp adbase::Timestamp::now ( )
static
time_t adbase::Timestamp::secondsSinceEpoch ( ) const
inline

获取 Timestamp 秒数

Returns
秒数

Definition at line 121 of file Timestamp.hpp.

References kMicroSecondsPerSecond, and now().

void adbase::Timestamp::swap ( Timestamp that)
inline

交换 Timestamp

Parameters
that交换 Timestamp
Returns
void
Example
std::cout << "t1:" << t1.toFormattedString() << std::endl;
std::cout << "t2:" << t2.toFormattedString() << std::endl;
t1.swap(t2);
std::cout << "t1:" << t1.toFormattedString() << std::endl;
std::cout << "t2:" << t2.toFormattedString() << std::endl;
// output
t1:20160603 21:54:47.302422
t2:20160603 21:59:47.302422
t1:20160603 21:59:47.302422
t2:20160603 21:54:47.302422

Definition at line 53 of file Timestamp.hpp.

References toFormattedString(), and toString().

std::string adbase::Timestamp::toFormattedString ( bool  showMicroseconds = true) const

Timestamp 格式化为可视化字符串

Parameters
showMicroseconds是否显示微妙
Returns
转化为字符串
Example
adbase::Timestamp time(10000010);
std::cout << time.toFormattedString() << std::endl;
// output 19700101 00:00:10.000010

Definition at line 25 of file Timestamp.cpp.

References kMicroSecondsPerSecond.

Referenced by swap().

std::string adbase::Timestamp::toString ( ) const

Timestamp 转化为字符串

Returns
转化为字符串
Example
adbase::Timestamp time(10000010);
std::cout << time.toString() << std::endl;
// output 10.000010

Definition at line 14 of file Timestamp.cpp.

References kMicroSecondsPerSecond.

Referenced by adbase::mc::ClientHandler::onMessage(), adbase::mc::Handler::onMessage(), adbase::head::Handler::onMessage(), and swap().

bool adbase::Timestamp::valid ( ) const
inline

判断 Timestamp 是否合法

Returns
判断是否合法,合法:true
Example
adbase::Timestamp invlidTime(-1);
if (invlidTime.valid()) {
std::cout << "Timestamp valid" << std::endl;
} else {
std::cout << "Timestamp invalid" << std::endl;
}

Definition at line 101 of file Timestamp.hpp.

Member Data Documentation

const int adbase::Timestamp::kMicroSecondsPerSecond = 1000 * 1000
static

The documentation for this class was generated from the following files: