您的位置:首页 > 编程语言 > C语言/C++

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

2016-08-21 17:15 786 查看
<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">}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: