Skip to content

Commit b40fc70

Browse files
authored
std.time: add microTimestamp() (#13327)
1 parent 98b6099 commit b40fc70

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/std/time.zig

+9
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ pub fn milliTimestamp() i64 {
7373
return @intCast(i64, @divFloor(nanoTimestamp(), ns_per_ms));
7474
}
7575

76+
/// Get a calendar timestamp, in microseconds, relative to UTC 1970-01-01.
77+
/// Precision of timing depends on the hardware and operating system.
78+
/// The return value is signed because it is possible to have a date that is
79+
/// before the epoch.
80+
/// See `std.os.clock_gettime` for a POSIX timestamp.
81+
pub fn microTimestamp() i64 {
82+
return @intCast(i64, @divFloor(nanoTimestamp(), ns_per_us));
83+
}
84+
7685
/// Get a calendar timestamp, in nanoseconds, relative to UTC 1970-01-01.
7786
/// Precision of timing depends on the hardware and operating system.
7887
/// On Windows this has a maximum granularity of 100 nanoseconds.

0 commit comments

Comments
 (0)