[ale] Need to convert standard time to epoch in bash
Christopher Fowler
cfowler at outpostsentinel.com
Tue Apr 17 11:08:02 EDT 2007
Here it is no perl used!
[cfowler at shuttle tmp]$ sh time.sh
1176822360
[cfowler at shuttle tmp]$ cat time.sh
#!/bin/sh
cat >/tmp/ti.c << EOF
#include <time.h>
int main(int argc, char **argv) {
struct tm t;
int ti;
t.tm_mon = atoi(argv[1]) - 1;
t.tm_mday = atoi(argv[2]);
t.tm_year = atoi(argv[3]) - 1900;
t.tm_hour = atoi(argv[4]);
t.tm_min = atoi(argv[5]);
t.tm_sec = atoi(argv[6]);
t.tm_isdst = 1;
ti = mktime(&t);
printf("%d\n", ti);
}
EOF
gcc -o /tmp/ti /tmp/ti.c || exit 1
EPOCH=`/tmp/ti 04 17 2007 11 06 00`
rm /tmp/ti 2>/dev/null
echo $EPOCH
On Tue, 2007-04-17 at 10:52 -0400, Ned Williams wrote:
> Greeting ale friends,
>
> I need to add function to a script with*out* using perl to convert
> standard time to UNIX Epoch time...anyone have code to do this?
>
> I can find plenty of examples as well as the date command intself to
> convert epoch to time but not the other way around
>
> help,
> Ned
>
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale
More information about the Ale
mailing list