|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
* c# v# b$ J* e# @) o" s" A
0 L4 Y5 L0 q( V2 q6 R* |: t0 Z$ Q3 T A5 G; e
. u# T0 c( n) M) X6 m
- #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, 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;
- }
1 h& n) n2 I7 |9 f( d- Z8 e
$ S) r- X4 o: X- s2 M; Z& H5 r# O8 J' p8 g0 Z
4 @1 p! O7 u: z; ~
n, u" Z$ r7 n3 i, t% F( U& k' E3 j
root@libang-virtual-machine:~/test/test# gcc compile.c ) D6 j- C8 ^7 P5 X
root@libang-virtual-machine:~/test/test# ./a.out
* P: t% B0 u( Z# f: GCompile time is = 2016-8-23 14:43:18
5 j0 c' p. E$ d S- K+ @/ X& B* o6 \
, p6 T* \: @% n& }
4 R% i8 y3 L5 H7 e% t& E
0 g- j) ^. z2 J7 F
' q% b( S- p) L* G6 c- ~- o0 Q 7 x# ]# U8 G. x( \' n
! u' s9 i* ]' C/ i1 i4 d% ~ |
|