本文整理汇总了C++中time_duration_type::seconds方法的典型用法代码示例。如果您正苦于以下问题:C++ time_duration_type::seconds方法的具体用法?C++ time_duration_type::seconds怎么用?C++ time_duration_type::seconds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类time_duration_type
的用法示例。
在下文中一共展示了time_duration_type::seconds方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: duration_put
//! Put time into an ostream
static void duration_put(const time_duration_type& td,
ostream_type& os)
{
if(td.is_special()) {
os << td.get_rep();
}
else {
charT fill_char = '0';
if(td.is_negative()) {
os << '-';
}
os << std::setw(2) << std::setfill(fill_char)
<< absolute_value(td.hours()) << ":";
os << std::setw(2) << std::setfill(fill_char)
<< absolute_value(td.minutes()) << ":";
os << std::setw(2) << std::setfill(fill_char)
<< absolute_value(td.seconds());
fractional_seconds_type frac_sec =
absolute_value(td.fractional_seconds());
if (frac_sec != 0) {
os << "."
<< std::setw(time_duration_type::num_fractional_digits())
<< std::setfill(fill_char)
<< frac_sec;
}
} // else
} // duration_put
示例2: duration_put
//! Put time into an ostream
static void duration_put(const time_duration_type& td,
ostream_type& os)
{
os << std::setw(2) << std::setfill('0') << td.hours() << ":";
os << std::setw(2) << std::setfill('0') << td.minutes() << ":";
os << std::setw(2) << std::setfill('0') << td.seconds();
fractional_seconds_type frac_sec = td.fractional_seconds();
if (frac_sec != 0) {
os << "." << std::setw(time_duration_type::num_fractional_digits())
<< std::setfill('0')
<< frac_sec;
}
} // duration_put
示例3: utc_to_local
typedef typename date_type::duration_type date_duration_type;
//! Convert a utc time to local time
static time_type utc_to_local(const time_type& t)
{
date_type time_t_start_day(1970,1,1);
time_type time_t_start_time(time_t_start_day,time_duration_type(0,0,0));
if (t < time_t_start_time) {
boost::throw_exception(std::out_of_range("Cannot convert dates prior to Jan 1, 1970"));
BOOST_DATE_TIME_UNREACHABLE_EXPRESSION(return time_t_start_time); // should never reach
}
date_duration_type dd = t.date() - time_t_start_day;
time_duration_type td = t.time_of_day();
uint64_t t2 = static_cast<uint64_t>(dd.days())*86400 +
static_cast<uint64_t>(td.hours())*3600 +
static_cast<uint64_t>(td.minutes())*60 +
td.seconds();
// detect y2038 issue and throw instead of proceed with bad time
std::time_t tv = boost::numeric_cast<std::time_t>(t2);
std::tm tms, *tms_ptr;
tms_ptr = c_time::localtime(&tv, &tms);
date_type d(static_cast<unsigned short>(tms_ptr->tm_year + 1900),
static_cast<unsigned short>(tms_ptr->tm_mon + 1),
static_cast<unsigned short>(tms_ptr->tm_mday));
time_duration_type td2(tms_ptr->tm_hour,
tms_ptr->tm_min,
tms_ptr->tm_sec,
t.time_of_day().fractional_seconds());
return time_type(d,td2);
}
};
示例4: utc_to_local
public:
typedef typename time_type::time_duration_type time_duration_type;
typedef typename time_type::date_type date_type;
typedef typename date_type::duration_type date_duration_type;
//! Convert a utc time to local time
static time_type utc_to_local(const time_type& t)
{
date_type time_t_start_day(1970,1,1);
time_type time_t_start_time(time_t_start_day,time_duration_type(0,0,0));
if (t < time_t_start_time) {
boost::throw_exception(std::out_of_range("Cannot convert dates prior to Jan 1, 1970"));
BOOST_DATE_TIME_UNREACHABLE_EXPRESSION(return time_t_start_time); // should never reach
}
date_duration_type dd = t.date() - time_t_start_day;
time_duration_type td = t.time_of_day();
std::time_t t2 = dd.days()*86400 + td.hours()*3600 + td.minutes()*60 + td.seconds();
std::tm tms, *tms_ptr;
tms_ptr = c_time::localtime(&t2, &tms);
date_type d(static_cast<unsigned short>(tms_ptr->tm_year + 1900),
static_cast<unsigned short>(tms_ptr->tm_mon + 1),
static_cast<unsigned short>(tms_ptr->tm_mday));
time_duration_type td2(tms_ptr->tm_hour,
tms_ptr->tm_min,
tms_ptr->tm_sec,
t.time_of_day().fractional_seconds());
return time_type(d,td2);
}
};