[rescue] Help w/ computer time??
    Greg A. Woods 
    woods at weird.com
       
    Wed Apr 24 14:16:42 CDT 2002
    
    
  
[ On Wednesday, April 24, 2002 at 14:32:38 (-0500), Linc Fessenden wrote: ]
> Subject: [rescue] Help w/ computer time??
>
> Since I really suck w/ perl I was wondering if one of you might be able to
> help me quickly...
> I have a file full of unix dates (epoch) listed one on a line.  I need to
> get these converted to localtime.  Is there a quick and dirty for this
> somewhere that I just can't find?
on what system are you trying to do this?
On *BSD there's "date -r seconds-since-epoch" (and of course you can
adjust the output format as desired too)
The C code that does this (relavent bits, more or less just cut&pasted
from date.c, with turning it back into a compilable program left as an
excercise to the reader! ;-) is:
	time_t tval;
	char *format;
	char buf[BUFSIZ];
	tval = strtol(epoch_seconds_string, NULL, 0);
	format = "%a %b %e %H:%M:%S %Z %Y";
	(void) strftime(buf, sizeof(buf), format, localtime(&tval));
	(void) printf("%s\n", buf);
localtime() is plain old ANSI C, and strftime() is new to ISO C99 but
old to *BSD.
-- 
								Greg A. Woods
+1 416 218-0098;  <gwoods at acm.org>;  <g.a.woods at ieee.org>;  <woods at robohack.ca>
Planix, Inc. <woods at planix.com>; VE3TCP; Secrets of the Weird <woods at weird.com>
    
    
More information about the rescue
mailing list