1
2
3
4
5
6
7
8
9
10
11
12
|
#include<time.h>
#include<stdio.h>
#include<dos.h>
int
main()
{
time_t
timer;
struct
tm
*tblock;
timer =
time
(NULL);
tblock =
localtime
(&timer);
printf
(
"Local time is: %s"
,
asctime
(tblock));
return
0;
}
|
1
2
3
4
5
6
7
8
9
|
#include<stdio.h>
#include<time.h>
int
main()
{
time_t
t;
time
(&t);
printf
(
"Today's date and time: %s"
,
ctime
(&t));
return
0;
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
|
#include<time.h>
#include<stdio.h>
#include<windows.h>
int
main()
{
time_t
start, end;
system
(
"cls"
);
//清屏
time
(&start);
Sleep(5000);
//等待5秒,Sleep()函数包含在windows.h的头文件里,以毫秒为单位
time
(&end);
printf
(
"The difference is: %f seconds"
,
difftime
(end, start));
return
0;
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<dos.h>
char
*tzstr=
"TZ=PST8PDT"
;
int
main()
{
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;
}
|
1
2
3
4
5
6
7
8
9
10
|
#include<time.h>
#include<stdio.h>
#include<dos.h>
int
main()
{
time_t
t;
t =
time
(NULL);
//默认1970-1-1
printf
(
"The number of seconds since January1, 1970 is %ld"
, t);
return
0;
}
|
1
2
3
4
5
6
7
8
9
10
11
12
|
#include<time.h>
#include<stdlib.h>
#include<stdio.h>
int
main()
{
time_t
td;
putenv(
"TZ=PST8PDT"
);
tzset();
time
(&td);
printf
(
"Current time = %s"
,
asctime
(
localtime
(&td)));
return
0;
}
|