How do I convert dmesg timestamp to custom date format?

ukanth picture ukanth · Dec 15, 2012 · Viewed 132.5k times · Source

I am trying to understand the dmesg timestamp and find it hard to convert that to change it to java date/custom date format.

Sample dmesg log:

[14614.647880] airo(eth1): link lost (missed beacons)

So how do I convert 14614.647880 to a standard date?

Answer

user180100 picture user180100 · Dec 15, 2012

Understanding dmesg timestamp is pretty simple: it is time in seconds since the kernel started. So, having time of startup (uptime), you can add up the seconds and show them in whatever format you like.

Or better, you could use the -T command line option of dmesg and parse the human readable format.

From the man page:

-T, --ctime
    Print human readable timestamps. The timestamp could be inaccurate!

    The time source used for the logs is not updated after system SUSPEND/RESUME.