下面自我测试
| 返回程序启动到现在的运行时间是函数 | 将unix时间转化为字符时间 | 将格林时间转化为字符时间 | 将unix时间转化为格林时间 | 获取unix时间
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void Time_Text1()
{
struct tm t;
t.tm_sec = 30;
t.tm_min = 30;
t.tm_hour = 12;
t.tm_mday = 15;
t.tm_mon = 6;
t.tm_year = 10;
t.tm_wday = 1;
printf("时间:%s", asctime(&t));
}
void Time_Text2()
{
clock_t Begin, End;
Begin = clock();
printf("\n程序运行到main函数用时:%ldms\n", Begin);
for (size_t i = 0; i < SIZE_MAX; i++)
{
}
End = clock();
printf("\nmain函数用时:%ldms\n",End-Begin);
}
void Time_Text3()
{
time_t Curtime;
time(&Curtime);
printf("当前时间:%s", ctime(&Curtime));
}
void Time_Text4()
{
time_t Begin,End;
time(&Begin);
for (size_t i = 0; i < SIZE_MAX; i++)
{
}
time(&End);
printf("主函数用时:%d s",(int)difftime(End, Begin));
}
void Time_Text5()
{
time_t Curtime;
struct tm *My_tm;
time(&Curtime);
My_tm = gmtime(&Curtime);
printf("当前时间->%d:%d", My_tm->tm_hour + 8, My_tm->tm_min);
}
void Time_Text6()
{
time_t Curtime;
struct tm* My_tm;
time(&Curtime);
My_tm = localtime(&Curtime);
printf("当前时间->%d:%d", My_tm->tm_hour, My_tm->tm_min);
}
void Time_Text7()
{
time_t Curtime;
struct tm* My_tm;
time(&Curtime);
My_tm = localtime(&Curtime);
int Year;
int Month;
int Day;
printf("\n输入年:\n"); scanf_s("%d", &Year);
printf("\n输入月:\n"); scanf_s("%d", &Month);
printf("\n输入日:\n"); scanf_s("%d", &Day);
My_tm->tm_year = Year - 1900;
My_tm->tm_mon = Month - 1;
My_tm->tm_mday = Day;
mktime(My_tm);
printf("今天是周%d!", My_tm->tm_wday);
}
void Time_Text9()
{
time_t Time;
Time = time(NULL);
printf_s("距离1970-1-1 00:00:00 已经过去%d秒!", Time);
}
void TUME_TEXT()
{
Time_Text9();
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-53881.html