Convert UNIX epoch time
Posted on Saturday, May 06 @ 20:04:55 BST by
delimia |
|
How do I convert unix time to a readable format?
[poxley@celeste ~]$ EPOCH=`date +%s` [poxley@celeste ~]$ [poxley@celeste ~]$ echo $EPOCH 1146854736 [poxley@celeste ~]$ echo $EPOCH|awk '{print strftime("%c",$1)}' Fri 05 May 2006 07:45:36 PM BST
To adjust the time, plus or minus e.g
[poxley@celeste ~]$ tstamp=`date +%s` [poxley@celeste ~]$ (( adstamp =$tstamp - 86400 )) #less 24 hours [poxley@celeste ~]$ echo $adstamp|awk '{print strftime("%c",$1)}' Fri 05 May 2006 08:03:37 PM BST
Another method would be to use date -d:
[poxley@celeste ~]$ date -d '1970-01-01 sec' Thu Jan 1 00:00:01 BST 1970 [poxley@celeste ~]$ date +%s 1147027276 [poxley@celeste ~]$ date -d '1970-01-01 1147027276 sec' Sun May 7 18:41:16 BST 2006
|
| |
|
Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.
|
|