C语言学习:格式化时间

1 #include <io_utils.h> 2 #include <time_utils.h> 3 #include <time.h> 4 5 int main() { 6 long_time_t current_time_in_ms = TimeInMillisecond(); 7 int current_time_millisecond = current_time_in_ms % 1000; 8 time_t current_time; 9 time(¤t_time); 10 PRINT_LLONG(current_time); 11 12 struct tm *calendar_time = localtime(¤t_time); 13 PRINT_INT(calendar_time->tm_year); 14 PRINT_INT(calendar_time->tm_mon); 15 PRINT_INT(calendar_time->tm_mday); 16 PRINT_INT(calendar_time->tm_hour); 17 PRINT_INT(calendar_time->tm_min); 18 PRINT_INT(calendar_time->tm_sec); 19 20 puts(asctime(calendar_time)); 21 puts(ctime(¤t_time)); 22 23 //2020-11-09 06:59:47 24 char current_time_s[20]; 25 // size_t size = strftime(current_time_s, 20, "%Y-%m-%d %H:%M:%S", calendar_time); 26 size_t size = strftime(current_time_s, 20, "%F %T", calendar_time); 27 PRINT_INT(size); 28 puts(current_time_s); 29 30 //20201109070456 31 size_t size2 = strftime(current_time_s, 20, "%Y%m%d%H%M%S", calendar_time); 32 sprintf(current_time_s + 14, "%03d", current_time_millisecond); 33 PRINT_INT(size2); 34 puts(current_time_s); 35 return 0; 36 }
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!