fork download
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. int main() {
  5. const char *str_time = "20160907-05:00:54.123";
  6. unsigned int year, month, day, hour, minute, second, miliseconds;
  7.  
  8. if (std::sscanf(str_time, "%4u%2u%2u-%2u:%2u:%2u.%3u",
  9. &year, &month, &day, &hour, &minute, &second, &miliseconds) != 7)
  10. {
  11. std::cout << "Parse failed" << std::endl;
  12. }
  13. else
  14. {
  15. std::cout << year << month << day << "-" << hour << ":" << minute << ":"
  16. << second << "." << miliseconds << std::endl;
  17. }
  18. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
201697-5:0:54.123