forked from df7cb/sdate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocaltime.c
51 lines (41 loc) · 787 Bytes
/
localtime.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
/*
* Copyright (C) 1993 Christoph Berg <[email protected]>
* This program is free software, see COPYING for copyright terms.
*/
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define LEN 100
int main (int argc, char **argv)
{
char s[LEN];
struct tm t;
time_t ti;
char *format = "%F %T";
setlocale(LC_ALL, "");
ti = time(NULL);
localtime_r(&ti, &t);
/*
if((t.tm_year == 93 && t.tm_mon == 8) || t.tm_year > 93) {
struct tm sep93 = { 0, 0, 0,
31, 7, 93,
0, 0, 0
};
time_t epoch = mktime(&sep93);
int d = (int)((ti - epoch) / 86400);
t.tm_year = 93;
t.tm_mon = 8;
t.tm_mday = d;
}
*/
if(argc > 2)
exit(2);
if(argc == 2)
format = argv[1];
if(strftime(s, LEN, format, &t) == 0) {
exit(1);
}
puts(s);
return 0;
}