-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdate.c
81 lines (64 loc) · 1.53 KB
/
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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <time.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
void date(char *arr[])
{
time_t current_time;
char date[1000];
time(¤t_time);
if (arr[1] != NULL)
{
if (!strcmp(arr[1], "-u\n") || !strcmp(arr[1], "-u"))
{
struct tm *date_time = gmtime(¤t_time);
strftime(date, sizeof(date), "%c", date_time);
for (int i = 0; i < 25; i++)
{
if (i == 19)
{
printf(" UTC ");
}
else
{
printf("%c", date[i]);
}
}
printf("\n");
}
else if (!strcmp(arr[1], "-I\n") || !strcmp(arr[1], "-I"))
{
struct tm *date_time = localtime(¤t_time);
strftime(date, sizeof(date), "%F", date_time);
printf("%s\n", date);
}
else
{
printf("date: invalid option %s\n", arr[1]);
}
}
else
{
struct tm *date_time = localtime(¤t_time);
strftime(date, sizeof(date), "%c", date_time);
for (int i = 0; i < 25; i++)
{
if (i == 19)
{
printf(" IST ");
}
else
{
printf("%c", date[i]);
}
}
printf("\n");
}
}
int main(int argc, char *argv[])
{
char *arr[] = {argv[1], argv[2]};
date(arr);
return 0;
}