c++中#include<time_h>中具体有那些用法

最好副例子
2024-12-01 01:06:39
推荐回答(3个)
回答1:

在void
begin();/*初始页和帮助*/
语做中唤句下添加
void
begin()
还有,你的主函数是int
类型,在最培源后要加上return
语句。纯凯

回答2:

你指的是time.h中的函数的用法吗?
请你打开改头文件(记事本都行),就可以看到里穗纤面知友有什么函数了。
有点多,搭族槐要有耐心看。

回答3:

time
ctime
difftime
gmtime
localtime
stime

gettime
settime

1. time
int main(void)
{
time_t t;

t = time(NULL);
printf("The number of seconds since January 1, 1970 is %ld",t);
return 0;
}
2. asctime
#include
#include <闭谈信time.h>
#include

int main(void)
{
struct tm t;
char str[80];

/* sample loading of tm structure */

t.tm_sec = 1; /* Seconds */
t.tm_min = 30; /* Minutes */
t.tm_hour = 9; /* Hour */
t.tm_mday = 22; /* Day of the Month */
t.tm_mon = 11; /* Month */
t.tm_year = 56; /* Year - does not include century */
t.tm_wday = 4; /* Day of the week */
t.tm_yday = 0; /* Does not show in asctime */

t.tm_isdst = 0; /轿轮* Is Daylight SavTime; does not show in asctime */

/* converts structure to null terminated string */

strcpy(str, asctime(&t));
printf("%s\n", str);

return 0;
}
3. ctime
#include
#include

int main(void)
{
time_t t;

time(&t);
printf("Today's date and time: %s\n", ctime(&t));
return 0;
}
4. difftime
#include
#include
#include
#include <侍握conio.h>

int main(void)
{
time_t first, second;

clrscr();
first = time(NULL); /* Gets system
time */
delay(2000); /* Waits 2 secs */
second = time(NULL); /* Gets system time
again */

printf("The difference is: %f seconds\n",difftime(second,first));
getch();

return 0;
}
5. gmtime
#include
#include
#include

/* Pacific Standard Time & Daylight Savings */
char *tzstr = "TZ=PST8PDT";

int main(void)
{
time_t t;
struct tm *gmt, *area;

putenv(tzstr);
tzset();

t = time(NULL);
area = localtime(&t);
printf("Local time is: %s", asctime(area));
gmt = gmtime(&t);
printf("GMT is: %s", asctime(gmt));
return 0;
}
6. localatime
#include
#include

int main(void)
{
time_t timer;
struct tm *tblock;

/* gets time of day */
timer = time(NULL);

/* converts date/time to a structure */
tblock = localtime(&timer);

printf("Local time is: %s", asctime(tblock));

return 0;
}
非标准函数
1. gettime
#include
#include

int main(void)
{
struct time t;

gettime(&t);
printf("The current time is: %2d:%02d:%02d.%02d\n",
t.ti_hour, t.ti_min, t.ti_sec, t.ti_hund);
return 0;
}
2. settime
#include
#include

int main(void)
{
struct time t;

gettime(&t);
printf("The current minute is: %d\n", t.ti_min);
printf("The current hour is: %d\n", t.ti_hour);
printf("The current hundredth of a second is: %d\n", t.ti_hund);
printf("The current second is: %d\n", t.ti_sec);

/* Add one to the minutes struct element and then call settime */
t.ti_min++;
settime(&t);

return 0;
}