//* 方法一
char *temp =new char[60];
time_t Time= time(NULL);//这句返回的只是一个时间cuotm * t= localtime(&Time);
sprintf(temp,"%4d%02d%02d%02d%02d%02d",t->tm_year+1900,
t->tm_mon+1,
t->tm_mday,
t->tm_hour,
t->tm_min,
t->tm_sec);
//* 方法二
char *temp =new char[60];
GetLocalTime(&Time);
sprintf(temp,"%d-%02d-%02d %02d:%02d:%02d\n",
Time.wYear,
Time.wMonth,
Time.wDay,
Time.wHour,
Time.wMinute,
Time.wSecond);
方法二中调用了Windows API,这点上是一个缺点,方法一使用的的C库,这个可以避免像Windows API 的故障问题不可挽回的缺点。
本文对比了使用C库和WindowsAPI获取当前时间的方法,并分析了各自的优势和劣势,强调了C库在避免特定操作系统的依赖方面的优势。
1755

被折叠的 条评论
为什么被折叠?



