2008年6月13日 星期五

顯示時間值


#include <stdio.h>
#include <time.h>

main()
{
time_t now;
char *cnow;
struct tm *stime;
time_t nnow;
time_t mnow;
time_t daystart;

now = time(NULL);
printf("time(NULL) = %d\n",now);

cnow = ctime(&now);
printf("ctime(&now) = %s",cnow);

stime = localtime(&now);
printf("stime : tm_sec = %d, tm_min = %d, tm_hour = %d, tm_mday = %d, tm_mon = %d, tm_year = %d\n",stime->tm_sec,stime->tm_min,stime->tm_hour,stime->tm_mday,stime->tm_mon,stime->tm_year);

nnow = mktime(stime);
printf("nnow = %d\n",nnow);

stime->tm_hour = 0;
stime->tm_min = 0;
stime->tm_sec = 0;

mnow = mktime(stime);
printf("mnow = %d\n",mnow);
}

沒有留言: