-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
timeGet.c
68 lines (59 loc) · 1.38 KB
/
timeGet.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <stdbool.h>
#include "file.h"
#include "config.h"
char *getDate(int date_form); // get current date
char *getHours_note(); // get current hours (HH:MM)
char *getHours(); // get current Hours
char *getMins(); // get current minutes
char *getDate(int date_form)
{
char *dateNote=malloc(sizeof(char) * 6);
time_t t;
t=time(NULL);
struct tm tm = *localtime(&t);
switch (date_form) {
case 1:
sprintf(dateNote, "%d-%d-%d", tm.tm_mday,tm.tm_mon+1,tm.tm_year+1900);
break;
case 2:
sprintf(dateNote, "%d-%d-%d", tm.tm_mon+1,tm.tm_mday,tm.tm_year+1900);
break;
case 3:
sprintf(dateNote, "%d-%d-%d", tm.tm_year+1900, tm.tm_mon+1,tm.tm_mday);
break;
default:
printerr("the date format is invalid",-1);
}
return dateNote;
}
char *getHours_note()
{
char *hourNote=malloc(sizeof(char) * 3);
time_t t;
t=time(NULL);
struct tm tm = *localtime(&t);
sprintf(hourNote, "%d:%d", tm.tm_hour,tm.tm_min);
return hourNote;
}
char *getHours()
{
time_t t;
char *hourNote=malloc(sizeof(char));
t=time(NULL);
struct tm tm = *localtime(&t);
sprintf(hourNote, "%d", tm.tm_hour);
return hourNote;
}
char *getMins()
{
time_t t;
char *minNote=malloc(sizeof(char));
t=time(NULL);
struct tm tm = *localtime(&t);
sprintf(minNote, "%d", tm.tm_min);
return minNote;
}