test for time.h

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
      time_t t; //you will find the statement "typedef long time_t;" in time.h
      time_t start, end;
      struct tm *ptr; //you will find the definition of struct tm in time.h
      time(&t); //get current time save it into "t", now t is equal to senconds between current time and January 1 1970

      ptr = localtime(&t); //you will find the definition of localtime() in time.h
      printf("The local time is %s", asctime(ptr));
      time(&start);
      time(&end);
      printf("please wait for 3 senonds ...\n");
      while(end - start <= 3)
      {
            static int temp = 0;
            if(temp != end - start)
            {
                  printf("%d ", 3 - (end - start));
                  temp = end - start;
            }
            time(&end);
            putchar(8);
      }
      return 0;
}

你可能感兴趣的:(职场,休闲)