Commit | Line | Data |
---|---|---|
e9c166c0 SBS |
1 | #!/bin/bash |
2 | # Desc: Get timestamp in nanoseconds | |
3 | ||
4caeddd7 | 4 | timeEpochNS() { |
e9c166c0 | 5 | # Desc: Get epoch nanoseconds |
4caeddd7 | 6 | # Usage: timeEpochNS |
d0dc71da | 7 | # Version 0.1.2 |
e9c166c0 SBS |
8 | # Input: (none) |
9 | # Output: Nanoseconds since 1970-01-01 | |
10 | # Depends: date 8 | |
d0dc71da | 11 | local currentTime epochSeconds fracNanosec epochNanosec |
e9c166c0 SBS |
12 | currentTime="$(date +%s.%N)"; |
13 | epochSeconds="$(echo "$currentTime" | cut -d. -f1)"; | |
14 | fracNanosec="$(echo "$currentTime" | cut -d. -f2)"; | |
15 | epochNanosec="$(( ("$epochSeconds" * 1000000000) + ("$fracNanosec") ))"; | |
16 | echo "$epochNanosec"; | |
aec895f5 | 17 | } # Nanoseconds since 1970-01-01 |
e9c166c0 SBS |
18 | |
19 | #==BEGIN sample code== | |
4caeddd7 | 20 | echo "It's been $(timeEpochNS) nanoseconds since 1970-01-01."; |
e9c166c0 | 21 | #==END sample code== |
5b497be8 SBS |
22 | |
23 | # Author: Steven Baltakatei Sandoval | |
24 | # License: GPLv3+ |