-
Notifications
You must be signed in to change notification settings - Fork 0
/
time.c
42 lines (31 loc) · 877 Bytes
/
time.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include <time.h>
char *gdbus_api_getCurrentTime()
{
time_t now;
struct tm *tm_now;
char datetime[256] = {0};
time(&now);
tm_now = localtime(&now);
strftime(datetime, sizeof(datetime), "%Y-%m-%d %H:%M:%S", tm_now);
printf("now datetime : %s\n", datetime);
return datetime;
}
int main(void)
{
time_t now;
struct tm *tm_now;
char datetime[200];
time(&now);
tm_now = localtime(&now);
strftime(datetime, 200, "%x %X %n%Y-%m-%d %H:%M:%S %nzone: %Z\n", tm_now);
printf("now datetime : %s\n", datetime);
char datetime2[200] = {0};
strftime(datetime2, 200, "%Y-%m-%d %H:%M:%S", tm_now);
printf("now datetime : %s\n", datetime2);
// time_t timep;
// time (&timep);
// printf("time: %s...",asctime(gmtime(&timep)));
printf("data from function : %s", gdbus_api_getCurrentTime);
return(0);
}