当前位置: 首页>>代码示例>>C++>>正文


C++ TimeStamp::encode方法代码示例

本文整理汇总了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, &times))
	{
		report_error("localtime_r");
		return result;
	}

	result.encode(&times, fractions);
#else
	struct tm *times = localtime(&seconds);
	if (!times)
	{
		report_error("localtime");
		return result;
	}

	result.encode(times, fractions);
#endif

	return result;
}
开发者ID:ASSmodeus,项目名称:dsploit,代码行数:57,代码来源:timestamp.cpp


注:本文中的TimeStamp::encode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。