File: localtime.c

package info (click to toggle)
sdate 0.4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,036 kB
  • ctags: 64
  • sloc: sh: 3,008; ansic: 149; makefile: 65; perl: 18
file content (51 lines) | stat: -rw-r--r-- 787 bytes parent folder | download | duplicates (5)
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 <cb@df7cb.de>
 * 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;
}