本文介绍了如何打印毫秒使用C?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在格式为hh打印时间:MM:SS:ms(毫秒)。我可以打印格式为HH:MM:SS。有什么可以打印剩余毫秒的方式吗?


解决方案

 #包括LT&; SYS / timeb.h>
#包括LT&;&time.h中GT;诠释主要(无效){
    结构TIMEB TP;
    FTIME(安培; TP);
    焦炭TIMESTRING [80];
    的strftime(TIMESTRING,sizeof的(TIMESTRING),%H:%M:%S,本地时间(安培; tp.time));
    的printf(%S:%D,TIMESTRING,tp.millitm);
    返回0;
}

I want to print time in the format hh:mm:ss:ms(milliseconds). I could print in the form of hh:mm:ss. What can be the way to print remaining milliseconds?

解决方案
#include<sys/timeb.h>
#include<time.h>

int main(void) {
    struct timeb tp;
    ftime(&tp);
    char timeString[80];
    strftime(timeString, sizeof(timeString), "%H:%M:%S", localtime(&tp.time));
    printf("%s:%d", timeString, tp.millitm);
    return 0;
}

这篇关于如何打印毫秒使用C?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 09:54