把系统时间存入数组中
#include<time.h>
#include <string.h>
int main()
{
time_t t;
char buf[128];
memset(buf,0,sizeof(buf));
struct tm *tmp;
t = time(NULL);
tmp = localtime(&t);
strftime(buf,sizeof(buf),"%Y-%m-%d %H:%M:%S",tmp);
return 0;
}
显示系统时间
#include<time.h>
#include <string.h>
#include<stdio.h>
int main()
{
time_t t;
struct tm * st;
time (&t);
st = localtime (&t);
printf ( "%d/%d/%d %d:%d:%d\n",st->tm_year+1900, st->tm_mon, st->tm_mday, st->tm_hour, st->tm_min, st->tm_sec);
return 0;
}
把系统时间存入数组中然后再通过数组显示时间
#include<time.h>
#include <string.h>
int main()
{
time_t t;
char buf[128];
memset(buf,0,sizeof(buf));
struct tm *tmp;
t = time(NULL);
tmp = localtime(&t);
strftime(buf,sizeof(buf),"%Y-%m-%d %H:%M:%S",tmp);
printf("%S",buf);
return 0;
}