aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorEric Milliken <11590808+mllken@users.noreply.github.com>2022-11-02 22:20:19 +0000
committerGitHub <noreply@github.com>2022-11-02 23:20:19 +0100
commitb40fc70188fd097e9e05b5c18b635b67b718380e (patch)
treeb829f466324a689e4d9acb656e675e1681937570 /lib/std
parent98b60992b334df16db1c7f99be466d252d61c4bc (diff)
downloadzig-b40fc70188fd097e9e05b5c18b635b67b718380e.tar.gz
zig-b40fc70188fd097e9e05b5c18b635b67b718380e.zip
std.time: add microTimestamp() (#13327)
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/time.zig9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/std/time.zig b/lib/std/time.zig
index ea830d9dd3..5f86c25b8d 100644
--- a/lib/std/time.zig
+++ b/lib/std/time.zig
@@ -73,6 +73,15 @@ pub fn milliTimestamp() i64 {
return @intCast(i64, @divFloor(nanoTimestamp(), ns_per_ms));
}
+/// Get a calendar timestamp, in microseconds, relative to UTC 1970-01-01.
+/// Precision of timing depends on the hardware and operating system.
+/// The return value is signed because it is possible to have a date that is
+/// before the epoch.
+/// See `std.os.clock_gettime` for a POSIX timestamp.
+pub fn microTimestamp() i64 {
+ return @intCast(i64, @divFloor(nanoTimestamp(), ns_per_us));
+}
+
/// Get a calendar timestamp, in nanoseconds, relative to UTC 1970-01-01.
/// Precision of timing depends on the hardware and operating system.
/// On Windows this has a maximum granularity of 100 nanoseconds.