如何从字符串H中获取时间:M:S在C中

C K*_*C K 2 c string time

我需要从格式化为例如"00:53:12"的字符串中提取小时,分钟和秒到变量a,b和c.

我怎么会用C来解决这个问题呢?

提前致谢!

Céd*_*ien 7

你可以使用strptime

struct tm tm;

if (strptime("00:53:12", "%H:%M:%S", &tm) != NULL)
   printf("hour: %d; minutes: %d; seconds: %d;\n",
      tm.tm_hour, tm.tm_min, tm.tm_sec);
Run Code Online (Sandbox Code Playgroud)