Question Convert date to milliseconds (epoch millis)
mailsanchu opened this issue · 4 comments
mailsanchu commented
How do i get epoc milliseconds from a custom date
dateconv "20220518181552" -i '%Y%m%d%H%M%S' -f %rs
gives me epoch second But how do i get milli second
hroptatyr commented
Hi, pragmatically you could do
$ "20220518181552" -i '%Y%m%d%H%M%S' -f %s000
mailsanchu commented
That is good enough for me Closing the ticket Thank you
mailsanchu commented
Is there a way to convert epoch milliseconds to human readable? Something like 1679930053000
hroptatyr commented
Afraid not. The parser trick above doesn't even work because of ambiguity (it's unclear where %s ends and the milliseconds are supposed to start). The only way is to convert the timestamp to epoch time somehow. E.g. if the value is in a shell variable
$ x=1679930053000
$ dateconv @${x%???}
or if it comes on stdin, plug an awk in between:
$ echo 1679930053000 | awk '$0=substr($0,1,length($0)-3)' | dateconv -i %s