From: Steven Baltakatei Sandoval Date: Tue, 7 Jul 2020 02:06:34 +0000 (+0000) Subject: feat(unitproc):Add timeNanosec function X-Git-Tag: 0.3.0~55 X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/commitdiff_plain/e9c166c06dca9c644eeecff9788f609db70616cc?ds=inline;hp=-c feat(unitproc):Add timeNanosec function Returns nanoseconds since 1970-01-01 with 'date'. --- e9c166c06dca9c644eeecff9788f609db70616cc diff --git a/unitproc/bktemp-timeNanosec b/unitproc/bktemp-timeNanosec new file mode 100644 index 0000000..4e57b21 --- /dev/null +++ b/unitproc/bktemp-timeNanosec @@ -0,0 +1,19 @@ +#!/bin/bash +# Desc: Get timestamp in nanoseconds + +timeNanosec() { + # Desc: Get epoch nanoseconds + # Version 0.1.0 + # Input: (none) + # Output: Nanoseconds since 1970-01-01 + # Depends: date 8 + currentTime="$(date +%s.%N)"; + epochSeconds="$(echo "$currentTime" | cut -d. -f1)"; + fracNanosec="$(echo "$currentTime" | cut -d. -f2)"; + epochNanosec="$(( ("$epochSeconds" * 1000000000) + ("$fracNanosec") ))"; + echo "$epochNanosec"; +} + +#==BEGIN sample code== +echo "It's been $(timeNanosec) nanoseconds since 1970-01-01."; +#==END sample code==