-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdate.c
34 lines (32 loc) · 780 Bytes
/
date.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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
int main(int argc, char *argv[]) {
time_t n;
time(&n);
if (argc >= 3 && !strcmp(argv[1], "-d")) {
if (!strcmp(argv[2], "today")) {
printf("%s", ctime(&n));
} else if (!strcmp(argv[2], "now")) {
printf("%s", ctime(&n));
}
else if (!strcmp(argv[2], "tomorrow")) {
n += 86400;
printf("%s", ctime(&n));
} else if (!strcmp(argv[2], "yesterday")) {
n -= 86400;
printf("%s", ctime(&n));
} else {
printf("date: invalid identifier '%s'\n", argv[2]);
}
} else if (argc >= 2 && !strcmp(argv[1], "-u")) {
n -= 19800;
printf("UTC: ");
printf("%s", ctime(&n));
} else if (argc >= 2) {
printf("date: invalid flags/syntax\n");
} else {
printf("%s", ctime(&n));
}
}