-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDATE.c
More file actions
36 lines (33 loc) · 830 Bytes
/
Copy pathDATE.c
File metadata and controls
36 lines (33 loc) · 830 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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int main(int argc,char *argv[])
{
time_t t=time(NULL);
struct tm *timeInfo;
char printableTime[100];
if(argc==1)
{
timeInfo=localtime(&t);
strftime(printableTime,sizeof(printableTime),"%A %d %B %Y %l:%M:%S %p %Z",timeInfo);
printf("%s\n",printableTime);
}
else if(argc>2)
printf("Excess arguments recived\n");
else if(strcmp(argv[1],"-u")==0)
{
timeInfo=gmtime(&t);
strftime(printableTime,sizeof(printableTime),"%A %d %B %Y %l:%M:%S %p %Z",timeInfo);
printf("%s\n",printableTime);
}
else if(strcmp(argv[1],"-R")==0)
{
timeInfo=localtime(&t);
strftime(printableTime,sizeof(printableTime),"%a, %d %b %Y %H:%M:%S %z",timeInfo);
printf("%s\n",printableTime);
}
else
printf("Invalid argument recieved\n");
return 0;
}