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


C++ time_duration::total_nanoseconds方法代码示例

本文整理汇总了C++中time_duration::total_nanoseconds方法的典型用法代码示例。如果您正苦于以下问题:C++ time_duration::total_nanoseconds方法的具体用法?C++ time_duration::total_nanoseconds怎么用?C++ time_duration::total_nanoseconds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在time_duration的用法示例。


在下文中一共展示了time_duration::total_nanoseconds方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: secondsFromDuration

/**
 * Return the number of seconds in a time_duration, as a double, including
 * fractional seconds.
 */
double DateAndTime::secondsFromDuration(time_duration duration) {
#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
  // Nanosecond resolution
  return static_cast<double>(duration.total_nanoseconds()) / 1e9;
#else
  // Microsecond resolution
  return static_cast<double>(duration.total_microseconds()) / 1e6;
#endif
}
开发者ID:rosswhitfield,项目名称:mantid,代码行数:13,代码来源:DateAndTime.cpp

示例2: toString

std::string TimeConversion::toString(const boost::posix_time::ptime ts, const int secPrecision) const
{
	using namespace boost::posix_time;

	// determine the nanoseconds given in ts
	const int h = ts.time_of_day().hours();
	const int m = ts.time_of_day().minutes();
	const int s = ts.time_of_day().seconds();
	const time_duration r = time_duration(h, m, s);
	const time_duration rest = ts.time_of_day() - r;
	const int nanoseconds = int(rest.total_nanoseconds()); // not more than 1 bil nanoseconds here.

	return toString(to_tm(ts), nanoseconds, secPrecision);
}
开发者ID:jannickep,项目名称:snowbots,代码行数:14,代码来源:Time.cpp

示例3: nanosecondsFromDuration

/** time duration in nanoseconds. Duration is limited to
 * MAX_NANOSECONDS and MIN_NANOSECONDS to avoid overflows.
 * @param td :: time_duration instance.
 * @return an int64 of the number of nanoseconds
 */
int64_t DateAndTime::nanosecondsFromDuration(const time_duration &td) {
  int64_t nano;
#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
  // Nanosecond resolution
  nano = td.total_nanoseconds();
#else
  // Microsecond resolution
  nano = (td.total_microseconds() * 1000);
#endif
  // Use these limits to avoid integer overflows
  if (nano > MAX_NANOSECONDS)
    return MAX_NANOSECONDS;
  else if (nano < MIN_NANOSECONDS)
    return MIN_NANOSECONDS;
  else
    return nano;
}
开发者ID:rosswhitfield,项目名称:mantid,代码行数:22,代码来源:DateAndTime.cpp


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