本文整理汇总了C++中time_duration::fractional_seconds方法的典型用法代码示例。如果您正苦于以下问题:C++ time_duration::fractional_seconds方法的具体用法?C++ time_duration::fractional_seconds怎么用?C++ time_duration::fractional_seconds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类time_duration
的用法示例。
在下文中一共展示了time_duration::fractional_seconds方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: to_iso_string
/*!\ingroup time_format
*/
inline
std::string
to_iso_string(time_duration td)
{
std::ostringstream ss;
if(td.is_special()) {
/* simply using 'ss << td.get_rep()' won't work on compilers
* that don't support locales. This way does. */
// switch copied from date_names_put.hpp
switch(td.get_rep().as_special()) {
case not_a_date_time:
//ss << "not-a-number";
ss << "not-a-date-time";
break;
case pos_infin:
ss << "+infinity";
break;
case neg_infin:
ss << "-infinity";
break;
default:
ss << "";
}
}
else {
if(td.is_negative()) {
ss << '-';
}
ss << std::setw(2) << std::setfill('0')
<< date_time::absolute_value(td.hours());
ss << std::setw(2) << std::setfill('0')
<< date_time::absolute_value(td.minutes());
ss << std::setw(2) << std::setfill('0')
<< date_time::absolute_value(td.seconds());
//TODO the following is totally non-generic, yelling FIXME
time_duration::fractional_seconds_type frac_sec =
date_time::absolute_value(td.fractional_seconds());
if (frac_sec != 0) {
ss << "." << std::setw(time_duration::num_fractional_digits())
<< std::setfill('0')
<< frac_sec;
}
}// else
return ss.str();
}
示例2: sleep
/*!
\fn CPlayloop::sleep(int duration)
*/
int CPlayloop::sleep(time_duration duration)
{
int retval = 0;
if( !duration.is_negative() )
{
struct timespec ts_to_sleep, ts_remaining;
ts_to_sleep.tv_sec = duration.total_seconds();
ts_to_sleep.tv_nsec = duration.fractional_seconds();
//boost::date_time::time_resolutions
if (time_duration::resolution() == boost::date_time::micro) {
ts_to_sleep.tv_nsec *= 1000;
}
int retval = nanosleep( &ts_to_sleep, &ts_remaining);
if(retval != 0)
cerr << "nanosleep returned early due to a signal!" << endl;
}
return retval;
}