-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdate.c
More file actions
51 lines (45 loc) · 938 Bytes
/
date.c
File metadata and controls
51 lines (45 loc) · 938 Bytes
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
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/wait.h>
#include<fcntl.h>
#include<dirent.h>
#include <sys/stat.h>
#include<time.h>
int main(int argc, char* argv[])
{
if(argv[1]==NULL)
{
struct tm *local_time;
time_t curr;
curr=time(NULL);
local_time=localtime(&curr);
printf("%s",asctime(local_time));
}
else
{
if(!strcmp(argv[1],"-u"))
{
struct tm *g_time;
time_t now;
time(&now);
g_time=gmtime(&now);
printf("%s",asctime(g_time));
}
else if(!strcmp(argv[1],"+%d"))
{
struct tm *local_time;
time_t curr;
curr=time(NULL);
local_time=localtime(&curr);
printf("%d",local_time->tm_mday);
printf("\n");
}
else
{
printf("Invalid Option\n");
}
}
return 0;
}