| 1 | #!/bin/bash |
| 2 | # Desc: Get timestamp in nanoseconds |
| 3 | |
| 4 | timeEpochNS() { |
| 5 | # Desc: Get epoch nanoseconds |
| 6 | # Usage: timeEpochNS |
| 7 | # Version 0.1.2 |
| 8 | # Input: (none) |
| 9 | # Output: Nanoseconds since 1970-01-01 |
| 10 | # Depends: date 8 |
| 11 | local currentTime epochSeconds fracNanosec epochNanosec |
| 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"; |
| 17 | } # Nanoseconds since 1970-01-01 |
| 18 | |
| 19 | #==BEGIN sample code== |
| 20 | echo "It's been $(timeEpochNS) nanoseconds since 1970-01-01."; |
| 21 | #==END sample code== |
| 22 | |
| 23 | # Author: Steven Baltakatei Sandoval |
| 24 | # License: GPLv3+ |