struct tm和time_t的转换

时间:2023-01-21 21:27:00

#include<stdio.h>
#include<time.h>
void main()
{
    long t;
    time_t s;
    int i;
    short e;
    struct tm *ptm;
    e=i=t=time(NULL);
    ptm=gmtime(&t);             //取地址,即参数是指针
    printf("time的返回值long是:%ld/n",t);
    printf("time的返回值int是:%d/n",i);
    printf("time的返回值short是:%d/n",e);
    printf("秒(tm_sec):%d/n",ptm->tm_sec);
    printf("分(tm_min):%d/n",ptm->tm_min);
    printf("时(tm_hour):%d/n",ptm->tm_hour);
    printf("日(tm_mday):%d/n",ptm->tm_mday);
    printf("月(tm_mon):1+%d/n",ptm->tm_mon);
    printf("年(tm_year):1900+%d/n",ptm->tm_year);
    printf("星期(tm_wday):%d/n",ptm->tm_wday);
    printf("天数(tm_yday:%d/n",ptm->tm_yday);
    printf("夏令时标志(tm_isdst):%d/n",ptm->tm_isdst);
    s=mktime(ptm);          //取地址,即指针
    printf("time的返回值long是:%ld/n",s);
}