Archivo

Archivo para Diciembre, 2009

BASH: Convertir “Unix Timestamp” a “Date”

Miércoles, 2 de Diciembre de 2009 Sebas Sin comentarios

Tube muchos problemas con el proyecto de la utu por esto, porque tenian la version FC4 y no tiene la mitad de las cosas… hay varias formas de hacerlo…

perl -e “require ‘ctime.pl’; print &ctime($EPOCH);”

Perl method 2: use the scalar and localtime functions:

perl -e “print scalar(localtime($EPOCH))”

Awk has a wrapper for the standard C strftime function:

echo $EPOCH|awk ‘{print strftime(”%c”,$1)}’

Para probar cual te anda… ( Ojo los ” y ‘ de wordpress )

#!/bin/bash
EPOCH=1000000000
DATE=$(perl -e “require ‘ctime.pl’; print &ctime($EPOCH);”)
echo $DATE
DATE=$(perl -e “print scalar(localtime($EPOCH))”)
echo $DATE
DATE=$(echo $EPOCH|awk ‘{print strftime(”%c”,$1)}’)
echo $DATE

[update: Thanks to S. Maynard for reminding me of the proper use of quotes and how to avoid using the pipe...]
DATE=$(awk “BEGIN { print strftime(\”%c\”,$EPOCH) }”)


Otra forma de hacerlo
# date –date=’1970-01-01 1000000000 sec GMT’
Sat Sep 8 20:46:40 CDT 2001

Otra forma de hacerlo (No anda en Fedora 4 < )
# date -d @1000000042
Sun Sep  9 01:47:22 GMT 2001

Categories: Linux Tags: