猿问

请问我该怎么打印输出时分秒毫秒?

求大神,怎么样输出毫秒,比如14:10:12:5 14点10分12秒5毫秒

守候你守候我
浏览 219回答 2
2回答

眼眸繁星

#include<stdio.h>#include<Windows.h>int main(){SYSTEMTIME st;GetLocalTime(&st);printf("%d点%d分%d秒%d毫秒\n",st.wHour,st.wMinute,st.wSecond,st.wMilliseconds);&nbsp;return 0;}

烙印99

#include <stdio.h>&nbsp;&nbsp;#include <time.h>&nbsp;&nbsp;int main(){&nbsp;&nbsp;time_t rawtime;&nbsp;&nbsp;struct tm * timeinfo;&nbsp;&nbsp;time ( &rawtime );&nbsp;&nbsp;timeinfo = localtime ( &rawtime );&nbsp;&nbsp;printf ( "The current date/time is: %s", asctime (timeinfo) );return 0;}说明:time_t // 时间类型(time.h 定义)&nbsp;&nbsp;struct tm { // 时间结构,time.h 定义如下:&nbsp;&nbsp;int tm_sec;&nbsp;&nbsp;int tm_min;&nbsp;&nbsp;int tm_hour;&nbsp;&nbsp;int tm_mday;&nbsp;&nbsp;int tm_mon;&nbsp;&nbsp;int tm_year;&nbsp;&nbsp;int tm_wday;&nbsp;&nbsp;int tm_yday;&nbsp;&nbsp;int tm_isdst;&nbsp;&nbsp;}&nbsp;&nbsp;time ( &rawtime ); // 获取时间,以秒计,从1970年1月一日起算,存于rawtime&nbsp;&nbsp;localtime ( &rawtime ); //转为当地时间,tm 时间结构&nbsp;&nbsp;asctime() // 转为标准ASCII时间格式:&nbsp;&nbsp;//就是直接打印tm,tm_year 从1900年计算,所以要加1900,月tm_mon,从0计算,所以要加1
随时随地看视频慕课网APP
我要回答