Current system time in hex

Revision history
Tags: linux bash

Get current system time as HEX string

#!/bin/bash

# Get zero-padded hex string from date format
# Usage: f <format>
function f {
	printf %02X $(date +$1)
}

h=$(f %-H)
m=$(f %-M)
s=$(f %-S)

echo $h:$m:$s

Example

$ date && timestring
Thu Mar 23 14:34:02 CET 2017
0E:22:02

If you have any comments or feedback, please send me an e-mail. (stig at stigok dotcom).

Did you find any typos, incorrect information, or have something to add? Then please propose a change to this post.

Creative Commons License This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.