#include <time.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//时间结构体struct tm 说明:
int main()
{
time_t t;
struct tm *pt ;
char *pc ;
char* nowTime;
time(&t);
// pc=ctime(&t) ;
// printf("ctime:%s", pc );
pt=localtime(&t) ;
printf("year=%d\n", pt->tm_year+1900 );
printf("tm_mon=%d\n", pt->tm_mon +1 );
printf("tm_mday=%d\n", pt->tm_mday );
printf("tm_hour=%d\n", pt->tm_hour );
printf("tm_min=%d\n", pt->tm_min );
printf("tm_sec=%d\n", pt->tm_sec );
char cyear[5],cmon[5],cday[5],ch[5],cmin[5],cs[5];//,cday,ch,cmin,cs
sprintf(cyear,"%d",pt->tm_year+1900);
sprintf(cmon,"%d", pt->tm_mon+1);
sprintf(cday,"%d",pt->tm_mday);
sprintf(ch,"%d",pt->tm_hour);
sprintf(cmin,"%d",pt->tm_min);
sprintf(cs,"%d",pt->tm_sec);
// printf("111111111:%s\n",cyear);
strcat(strcat(strcat(strcat(strcat(cyear,"-"),cmon),"-"),cday)," ");
strcat(strcat(strcat(strcat(strcat(strcat(cyear,ch),":"),cmin),":"),cs),":");
printf("%s\n",cyear);
int year,mon,day,h,min,s,count;
const char* time ="2016-12-01 19:13:15 10"; //cyear; cyear;//
sscanf(time,"%d-%d-%d %d:%d:%d %d",&year,&mon,&day,&h,&min,&s,&count);
printf("year=%d\n", year );
printf("mon=%d\n", mon );
printf("day=%d\n", day );
printf("h=%d\n", h );
printf("min=%d\n", min );
printf("sec=%d\n", s );
printf("count=%d\n", count );
return 0;
}
// struct tm{
// int tm_sec; /* 秒 – 取值区间为[0,59] */
// int tm_min; /* 分 - 取值区间为[0,59] */
// int tm_hour; /* 时 - 取值区间为[0,23] */
// int tm_mday; /* 一个月中的日期 - 取值区间为[1,31] */
// int tm_mon; /* 月份(从一月开始,0代表一月) - 取值区间为[0,11] */
// int tm_year; /* 年份,其值等于实际年份减去1900 */
// int tm_wday; /* 星期 – 取值区间为[0,6],其中0代表星期天,1代表星期一,以此类推 */
// int tm_yday; /* 从每年的1月1日开始的天数 – 取值区间为[0,365],其中0代表1月1日,1代表1月2日,以此类推 */
// int tm_isdst; /* 夏令时标识符,实行夏令时的时候,tm_isdst为正。不实行夏令时的进候,tm_isdst为0;不了解情况时,tm_isdst()为负。*/
// };
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//时间结构体struct tm 说明:
int main()
{
time_t t;
struct tm *pt ;
char *pc ;
char* nowTime;
time(&t);
// pc=ctime(&t) ;
// printf("ctime:%s", pc );
pt=localtime(&t) ;
printf("year=%d\n", pt->tm_year+1900 );
printf("tm_mon=%d\n", pt->tm_mon +1 );
printf("tm_mday=%d\n", pt->tm_mday );
printf("tm_hour=%d\n", pt->tm_hour );
printf("tm_min=%d\n", pt->tm_min );
printf("tm_sec=%d\n", pt->tm_sec );
char cyear[5],cmon[5],cday[5],ch[5],cmin[5],cs[5];//,cday,ch,cmin,cs
sprintf(cyear,"%d",pt->tm_year+1900);
sprintf(cmon,"%d", pt->tm_mon+1);
sprintf(cday,"%d",pt->tm_mday);
sprintf(ch,"%d",pt->tm_hour);
sprintf(cmin,"%d",pt->tm_min);
sprintf(cs,"%d",pt->tm_sec);
// printf("111111111:%s\n",cyear);
strcat(strcat(strcat(strcat(strcat(cyear,"-"),cmon),"-"),cday)," ");
strcat(strcat(strcat(strcat(strcat(strcat(cyear,ch),":"),cmin),":"),cs),":");
printf("%s\n",cyear);
int year,mon,day,h,min,s,count;
const char* time ="2016-12-01 19:13:15 10"; //cyear; cyear;//
sscanf(time,"%d-%d-%d %d:%d:%d %d",&year,&mon,&day,&h,&min,&s,&count);
printf("year=%d\n", year );
printf("mon=%d\n", mon );
printf("day=%d\n", day );
printf("h=%d\n", h );
printf("min=%d\n", min );
printf("sec=%d\n", s );
printf("count=%d\n", count );
return 0;
}
// struct tm{
// int tm_sec; /* 秒 – 取值区间为[0,59] */
// int tm_min; /* 分 - 取值区间为[0,59] */
// int tm_hour; /* 时 - 取值区间为[0,23] */
// int tm_mday; /* 一个月中的日期 - 取值区间为[1,31] */
// int tm_mon; /* 月份(从一月开始,0代表一月) - 取值区间为[0,11] */
// int tm_year; /* 年份,其值等于实际年份减去1900 */
// int tm_wday; /* 星期 – 取值区间为[0,6],其中0代表星期天,1代表星期一,以此类推 */
// int tm_yday; /* 从每年的1月1日开始的天数 – 取值区间为[0,365],其中0代表1月1日,1代表1月2日,以此类推 */
// int tm_isdst; /* 夏令时标识符,实行夏令时的时候,tm_isdst为正。不实行夏令时的进候,tm_isdst为0;不了解情况时,tm_isdst()为负。*/
// };