小编Rwe*_*ale的帖子

如何获取 Howard Hinnant 日期的小数秒数

示例:从字符串中解析日期/时间,然后我想分解日期/时间的组成部分。似乎我得到了所有内容,但我陷入了小数秒的困境。代码如下

std::wistringstream in{ L"2016-12-11 15:43:22.0999919" };
date::sys_time<std::chrono::microseconds> tp;
in >> date::parse(L"%F %T", tp);
assert(!in.fail());
assert(!in.bad());

date::sys_days dp = date::floor<date::days>(tp);
date::year_month_day the_date = date::year_month_day{ dp };
date::time_of_day<std::chrono::microseconds> the_time = date::make_time(tp - dp);
std::cout << the_date << ' ' << the_time << std::endl;

std::cout << "Year: " << the_date.year() << std::endl;
std::cout << "Month: " << (unsigned)the_date.month() << std::endl;
std::cout << "Date: " << the_date.day() << std::endl;

std::cout << "Hour: " << the_time.hours().count() << std::endl;
std::cout << "Minutes: " << the_time.minutes().count() << …
Run Code Online (Sandbox Code Playgroud)

c++ date std

5
推荐指数
1
解决办法
665
查看次数

标签 统计

c++ ×1

date ×1

std ×1