69,739
社区成员
发帖
与我相关
我的任务
分享
int main(int argc, char **argv)
{
time_t t;
t = time(NULL);
struct tm *lt;
int ii = time(&t);
printf("ii = %d\n", ii);
t = time(NULL);
lt = localtime(&t);
char nowtime[24];
memset(nowtime, 0, sizeof(nowtime));
strftime(nowtime, 24, "%Y-%m-%d %H:%M:%S", lt);
printf("nowtime = %s\n", nowtime);
return 1;
}
// test.cpp : Defines the entry point for the console application.
#include <stdio.h>
#include <time.h>
int main(int argc, char* argv[])
{
struct tm lt;
time_t t;
char *timestr = "2011-12-31 11:43:07";
sscanf(timestr,"%d-%d-%d %d:%d:%d",<.tm_year,<.tm_mon,<.tm_mday,<.tm_hour,<.tm_min,<.tm_sec);
lt.tm_year-=1900;
lt.tm_mon-=1;
t=mktime(<);
printf("%d",t);
return 0;
}
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
long GetTick(char *str_time)
{
struct tm stm;
int iY, iM, iD, iH, iMin, iS;
memset(&stm,0,sizeof(stm));
iY = atoi(str_time);
iM = atoi(str_time+5);
iD = atoi(str_time+8);
iH = atoi(str_time+11);
iMin = atoi(str_time+14);
iS = atoi(str_time+17);
stm.tm_year=iY-1900;
stm.tm_mon=iM-1;
stm.tm_mday=iD;
stm.tm_hour=iH;
stm.tm_min=iMin;
stm.tm_sec=iS;
/*printf("%d-%0d-%0d %0d:%0d:%0d\n", iY, iM, iD, iH, iMin, iS);*/
return mktime(&stm);
}
int main()
{
char str_time[19];
printf("请输入时间:"); /*(格式:2011-12-31 11:43:07)*/
gets(str_time);
printf("%ld\n", GetTick(str_time));
return 0;
}
#include <stdio.h>
#include <time.h>
int main(int argc,char *argv[]){
struct tm lt;
time_t t;
char *timestr = "2011-12-31 11:43:07";
sscanf(timestr,"%d-%d-%d %d:%d:%d",<.tm_year,<.tm_mon,<.tm_mday,<.tm_hour,<.tm_min,<.tm_sec);
lt.tm_year-=1900;
lt.tm_mon-=1;
t=mktime(<);
printf("%d",t);
return 0;
}
#include <stdio.h>
#include <time.h>
#include <string.h>
long GetTick(int iY,int iM,int iD,int iH,int iMin,int iS)
{
struct tm stm;
memset(&stm,0,sizeof(stm));
stm.tm_year=iY-1900;
stm.tm_mon=iM-1;
stm.tm_mday=iD;
stm.tm_hour=iH;
stm.tm_min=iMin;
stm.tm_sec=iS;
return mktime(&stm);
}
int main()
{
printf("%d\n", GetTick(2011,12,31,11,43,7));
return 0;
}