2 # Desc: Get timestamp in nanoseconds
5 # Desc: Get epoch nanoseconds
8 # Output: Nanoseconds since 1970-01-01
10 local currentTime epochSeconds fracNanosec epochNanosec
11 currentTime
="$(date +%s.%N)";
12 epochSeconds
="$(echo "$currentTime" | cut -d. -f1)";
13 fracNanosec
="$(echo "$currentTime" | cut -d. -f2)";
14 epochNanosec
="$(( ("$epochSeconds" * 1000000000) + ("$fracNanosec") ))";
16 } # Nanoseconds since 1970-01-01
18 #==BEGIN sample code==
19 echo "It's been $(timeNanosec) nanoseconds since 1970-01-01.";
22 # Author: Steven Baltakatei Sandoval