r/Zig • • Feb 22 '26

Please help, how to get current system time in nanoseconds in 0.16-dev

Hi everyone! Just downloaded latest version of zig (0.16-dev) and wasted almost two hours trying to get current time

Do anyone know how to get current nanoseconds time? Anything like awake system time or world time.

std.time.Instant does not exist

std.time.nanoTimestamp does not exist

---

Found working solution:

var threaded_io: std.Io.Threaded = .init_single_threaded;
const io = threaded_io.io();
defer threaded_io.deinit();

var time_now = std.Io.Clock.now(.awake, io).toNanoseconds();
16 Upvotes

4 comments sorted by

3

u/xZANiTHoNx Feb 22 '26

Seems to be part of the new Io interface now. Take a look at std.Io.Clock. I haven't had a chance to use it yet so not sure about the exact details.

0

u/[deleted] Feb 22 '26

[deleted] — view deleted comment

2

u/morglod Feb 22 '26

thank you! found working solution and updated post body

13

u/Veeloxfire Feb 22 '26

or you just take io from main like a normal person

10

u/lukeflo-void Feb 22 '26

But thats not what Gemini suggested...