1fe077f41af24a8f22e2d7f8102b9f2a91803dac
[BK-2020-03.git] / unitproc / bktemp-timeNanosec
1 #!/bin/bash
2 # Desc: Get timestamp in nanoseconds
3
4 timeNanosec() {
5 # Desc: Get epoch nanoseconds
6 # Version 0.1.2
7 # Input: (none)
8 # Output: Nanoseconds since 1970-01-01
9 # Depends: date 8
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") ))";
15 echo "$epochNanosec";
16 } # Nanoseconds since 1970-01-01
17
18 #==BEGIN sample code==
19 echo "It's been $(timeNanosec) nanoseconds since 1970-01-01.";
20 #==END sample code==
21
22 # Author: Steven Baltakatei Sandoval
23 # License: GPLv3+