如何用C语言编写一个显示时间的函数,要求时间显示精度到毫秒级别。

Python014

如何用C语言编写一个显示时间的函数,要求时间显示精度到毫秒级别。,第1张

#include <cstdio>

#include <ctime>

using namespace std

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

void printTime() {

  struct tm t   //tm结构指针

time_t now  //声明time_t类型变量

time(&now)      //获取系统日期时间

localtime_s(&t, &now)   //获取当地日期和时间

   //格式化输出本地时间

printf("年-月-日-时-分-秒:%d-%d-%d %d:%d:%d\n", t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec)

}

int main(int argc, char** argv) {

printTime()

}

#include <stdio.h>

#include <time.h>

int main()

{

time_t rawtime

struct tm * timeinfo

time ( &rawtime )

timeinfo = localtime ( &rawtime )

printf ( "The current date/time is: %s", asctime (timeinfo) )

return 0

}