Linux下获取文件编译的时间
linux-dash
A beautiful web dashboard for Linux
项目地址:https://gitcode.com/gh_mirrors/li/linux-dash

·
#include <stdio.h>
#define MONTH_PER_YEAR 12 // 一年12月
#define YEAR_MONTH_DAY 20 // 年月日缓存大小
#define HOUR_MINUTES_SEC 20 // 时分秒缓存大小
void GetCompileTime(void)
{
const char year_month[MONTH_PER_YEAR][4] =
{ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
char compile_date[YEAR_MONTH_DAY] = {0}, compile_time[HOUR_MINUTES_SEC] = {0}, i;
char str_month[4] = {0};
int year, month, day, hour, minutes, seconds;
sprintf(compile_date, "%s", __DATE__); // "Aug 23 2016"
sprintf(compile_time, "%s", __TIME__); // "10:59:19"
sscanf(compile_date, "%s %d %d", str_month, &day, &year);
sscanf(compile_time, "%d:%d:%d", &hour, &minutes, &seconds);
for(i = 0; i < MONTH_PER_YEAR; ++i)
{
if(strncmp(str_month, year_month[i], 3) == 0)
{
month = i + 1;
break;
}
}
printf("Compile time is = %d-%d-%d %d:%d:%d\n", year, month, day, hour, minutes, seconds);
}
int main(void)
{
GetCompileTime();
return 0;
}
root@libang-virtual-machine:~/test/test# gcc compile.c root@libang-virtual-machine:~/test/test# ./a.out
Compile time is = 2016-8-23 14:43:18




A beautiful web dashboard for Linux
最近提交(Master分支:28 天前 )
186a802e
added ecosystem file for PM2 5 年前
5def40a3
Add host customization support for the NodeJS version 5 年前
更多推荐
所有评论(0)