clock函数的使用——C语言程序设计现代方法P493

/*编写一个程序显示当前时间*/

/*
/*Display the current date and time in one format*/
#include<stdio.h>
#include<time.h>

int main(void)
{
    time_t current = time(NULL);
    struct tm *ptr;
    char date_time[21];
    int hour;
    char am_or_pm;

   /*Print date and time in default format*/
   puts(ctime(&current));

   /*Print date and time, using printf to format*/
   strftime(date_time, sizeof(date_time), "%m-%d-%y %I:%M%P\n", localtime(&current));
   puts(date_time);

   return 0;

}

/*clock函数的用法*/

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

int main(void)
{
    clock_t start_clock = clock();
    printf("Processor time used:%g sec.\n", (clock() - start_clock) / (double) CLOCKS_PER_SEC);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/Eider1998/article/details/82560273
今日推荐