本文整理汇总了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
}
示例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);
}
示例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;
}