Page 1 of 1

[SOLVED] Converting timestamps to human-readable?

PostPosted: Mar 19th, '12, 03:23
by jaywalker
More logs are turning up with decimal numbers instead of dates and times. Is there a slick way to filter a log and convert these numbers into something human-readable? I imagine I will have to make readable copies of the logs, but it would be great if the log could just be piped through it to the screen.

In the meantime I'm going to try to make myself a ready-reckoner in Calc.

Richard

UPDATE
I found a ready-reckoner on the web: http://www.onlineconversion.com/unix_time.htm
And I discovered
Code: Select all
date -d "@1331776887.470"

All I need now is to bash it into shape :D

Re: Converting timestamps to human-readable?

PostPosted: Mar 19th, '12, 07:50
by doktor5000
Could you give an example for such a timestamp and where this is used?

Re: Converting timestamps to human-readable?

PostPosted: Mar 19th, '12, 16:15
by jaywalker
/var/log/ConsoleKit/history
/var/log/Xorg.0.log though here it is relative to, presumably, start of boot. That may take a bit more work than a simple filter, but then again, it is only once per boot.

Seems that is all. I got the impression there were more. Maybe there is some sort of clean-up activity we don't know about, or maybe I am just mistaken.

Re: Converting timestamps to human-readable?

PostPosted: Mar 21st, '12, 01:21
by jaywalker
Here's a solution for the /var/log/ConsoleKit/history log which works rather well.

First copy the file to your home directory and add a ".csv" suffix to the file name.
Next open LibreOffice Calc and use the Insert->Sheet from file... menu option to load your "csv" log.
The import wizard will split the log entries up into columns, and you can play with that if you like, but I didn't.
The important timestamp field will be column A.
To convert to a LibreOffice date value use this formula in column B
Code: Select all
=25569+(A1/86400)

Now all you have to do is format the cell in B1 with this custom format string;
Code: Select all
use Format->Cells and click on the Numbers tab
select Category->User Defined
Type in format code; YYYY-MMM-DD HH:MM:SS.000

Now you can copy the B1 cell to all of the cells in column B in the range covered by the log.

I'm happy now.