C语言实现获取系统时间,转换成时分秒年月日 (vs2015亲测可用)

时间:2021-06-13 13:42:20
<span style="color: rgb(51, 51, 51); font-family: 'Microsoft YaHei'; font-size: 14px; line-height: 24px;">基本思路:首先获取系统时钟,然后转换格式为:年月日时分秒(YYYYMMDDHHMMSS)</span>
<pre name="code" class="cpp"><span>#include <stdio.h>
#include <time.h>	</span>
int main()
{
time_t nowtime;struct tm timeinfo;time(&nowtime);localtime_s(&timeinfo,&nowtime);int year, month, day, hour, min, sec;year = 1900 + timeinfo.tm_year;month = 1 + timeinfo.tm_mon;day = timeinfo.tm_mday;hour = timeinfo.tm_hour;min = timeinfo.tm_min;sec = timeinfo.tm_sec;printf("系统时间:%4d-%02d-%02d %02d:%02d:%02d\n",year, month, day, hour, min, sec);
<span style="white-space:pre">	</span>return 0;<pre name="code" class="cpp">}