本文整理汇总了C++中TimeStamp::encode方法的典型用法代码示例。如果您正苦于以下问题:C++ TimeStamp::encode方法的具体用法?C++ TimeStamp::encode怎么用?C++ TimeStamp::encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimeStamp
的用法示例。
在下文中一共展示了TimeStamp::encode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getCurrentTimeStamp
TimeStamp TimeStamp::getCurrentTimeStamp()
{
TimeStamp result;
// NS: We round generated timestamps to whole millisecond.
// Not many applications can deal with fractional milliseconds properly and
// we do not use high resolution timers either so actual time granularity
// is going to to be somewhere in range between 1 ms (like on UNIX/Risc)
// and 53 ms (such as Win9X)
time_t seconds; // UTC time
int milliseconds;
#ifdef HAVE_GETTIMEOFDAY
struct timeval tp;
GETTIMEOFDAY(&tp);
seconds = tp.tv_sec;
milliseconds = tp.tv_usec / 1000;
#else
struct timeb time_buffer;
ftime(&time_buffer);
seconds = time_buffer.time;
milliseconds = time_buffer.millitm;
#endif
// NS: Current FB behavior of using server time zone is not appropriate for
// distributed applications. We should be storing UTC times everywhere and
// convert timestamps to client timezone as necessary. Replace localtime stuff
// with these lines as soon as the appropriate functionality is implemented
//
// mValue.timestamp_date = seconds / 86400 + GDS_EPOCH_START;
// mValue.timestamp_time = (seconds % 86400) * ISC_TIME_SECONDS_PRECISION;
const int fractions = milliseconds * ISC_TIME_SECONDS_PRECISION / 1000;
#ifdef HAVE_LOCALTIME_R
struct tm times;
if (!localtime_r(&seconds, ×))
{
report_error("localtime_r");
return result;
}
result.encode(×, fractions);
#else
struct tm *times = localtime(&seconds);
if (!times)
{
report_error("localtime");
return result;
}
result.encode(times, fractions);
#endif
return result;
}