# How to get the current (date)time and add one hour to it?

**URL:** <https://ziggit.dev/t/how-to-get-the-current-date-time-and-add-one-hour-to-it/13833>\
**Category:** Help\
**Tags:** standard-library\
**Created:** [January 6, 2026, 4:57pm UTC](https://ziggit.dev/t/how-to-get-the-current-date-time-and-add-one-hour-to-it/13833 "2026-01-06T16:57:26Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![saurabh](https://ziggit.dev/user_avatar/ziggit.dev/saurabh/32/4623_2.png) [@saurabh](https://ziggit.dev/u/saurabh)\
**Post date:** [January 6, 2026, 4:57pm UTC](https://ziggit.dev/t/how-to-get-the-current-date-time-and-add-one-hour-to-it/13833/1 "2026-01-06T16:57:26Z")

</div>

Hello, I’m looking to get the current (date)time and add one hour to it.

Its not clear going through [Io.Clock](https://ziglang.org/documentation/master/std/#std.Io.Clock), [Io.Duration](https://ziglang.org/documentation/master/std/#std.Io.Duration), [Io.Timeout](https://ziglang.org/documentation/master/std/#std.Io.Timeout), and [Io.Timestamp](https://ziglang.org/documentation/master/std/#std.Io.Timestamp).

Whats the simplest way to:

```zig
const start = // get current time
const end = // add 1 hour to it
print("Start: {any} End: {any}", .{start, end});

```

?

---

<div class="post-metadata">

**Author:** ![LucasSantos91](https://ziggit.dev/user_avatar/ziggit.dev/lucassantos91/32/440_2.png) [@LucasSantos91](https://ziggit.dev/u/LucasSantos91)\
**Post date:** [January 6, 2026, 5:07pm UTC](https://ziggit.dev/t/how-to-get-the-current-date-time-and-add-one-hour-to-it/13833/2 "2026-01-06T17:07:13Z")

</div>

You need an `Io` implementation, and only `Threaded` is reasonably complete at this moment.  
The `Io` interface is changing very rapidly. But as of this second, the way to do it is:

```zig
var t: std.Io.Threaded = .init_single_threaded;
const io = t.io();
const now = try io.vtable.now();
const one_hour : std.Io.Duration = .fromSeconds(60 * 60);
const now_plus_one_hour = now.addDuration(one_hour);

```

---

<div class="post-metadata">

**Author:** ![gonzo](https://ziggit.dev/user_avatar/ziggit.dev/gonzo/32/54_2.png) [@gonzo](https://ziggit.dev/u/gonzo)\
**Post date:** [January 6, 2026, 5:55pm UTC](https://ziggit.dev/t/how-to-get-the-current-date-time-and-add-one-hour-to-it/13833/3 "2026-01-06T17:55:56Z")

</div>

You can also use calls to “low level” C functions, at least for now (while these things are being reworked). Not necessarily the best way to do it, but it is always a last resort. So, something like (again, this is C code):

```c
time_t seconds = time(0);
seconds += 1 * 60 * 60;

```

---

<div class="post-metadata">

**Author:** ![numeralblue](https://ziggit.dev/user_avatar/ziggit.dev/numeralblue/32/6198_2.png) [@numeralblue](https://ziggit.dev/u/numeralblue)\
**Post date:** [January 7, 2026, 2:32am UTC](https://ziggit.dev/t/how-to-get-the-current-date-time-and-add-one-hour-to-it/13833/4 "2026-01-07T02:32:32Z")

</div>

[zeit](https://github.com/rockorager/zeit) can do that.

```zig
const std = @import("std");
const zeit = @import("zeit");

pub fn main() !void {
    const allocator = std.heap.page_allocator;
    var env = try std.process.getEnvMap(allocator);
    defer env.deinit();
    const local = try zeit.local(allocator, &env);

    const now = try zeit.instant(.{});
    const now2 = try now.add(.{
        .hours = 1,
    });
    const time = now2.time();
    var buffer: [100]u8 = undefined;
    var writer = std.Io.Writer.fixed(&buffer);
    try time.strftime(&writer, "%Y-%m-%d %H:%M:%S %Z");
    var buffer2 = buffer[0..writer.end];
    std.debug.print("{s}\n", .{buffer2}); // UTC

    const now3 = now2.in(&local);
    const time2 = now3.time();
    writer = std.Io.Writer.fixed(&buffer);
    try time2.strftime(&writer, "%Y-%m-%d %H:%M:%S %Z");
    buffer2 = buffer[0..writer.end];
    std.debug.print("{s}\n", .{buffer2}); // local
}

```

---

<div class="post-metadata">

**Author:** ![saurabh](https://ziggit.dev/user_avatar/ziggit.dev/saurabh/32/4623_2.png) [@saurabh](https://ziggit.dev/u/saurabh)\
**Post date:** [January 8, 2026, 3:00am UTC](https://ziggit.dev/t/how-to-get-the-current-date-time-and-add-one-hour-to-it/13833/5 "2026-01-08T03:00:39Z")

</div>

Thanks for linking it!

Surely making a library like that is a lot of work, and I’m not trying to downplay the effort put in by the contributors, but I have a few hard requirements - one of which is not using any third party library. My thinking is that if its part of the application then it needs to be worked on, not simply imported. I like Zig to the extent that I dont want to offload any work I can do using it.

Another downside is that libraries are likely (and rightly so) at a point release. I’m aiming to be as close to `master` as possible - especially to PRs labelled with ‘breaking’ and ‘release notes’. Incorporating a third party library would mean that I would have to watch two things instead of just Zig - and the speed at which Zig is moving, it would take a lot out of a person to do this. And also having a working project will be very tough.

The main thing is that for the stage Zig is in, third party libraries should not be promoted so that:

- end users understand exactly whats going on instead of working on an abstraction

- more users on the master branch means more bug reports which will make Zig even more solid

- agency and ownership - using dependencies reduces both and also defeats the purpose of being an early adopter

---

<div class="post-metadata">

**Author:** ![alanza](https://ziggit.dev/user_avatar/ziggit.dev/alanza/32/6006_2.png) [@alanza](https://ziggit.dev/u/alanza)\
**Post date:** [January 8, 2026, 4:13am UTC](https://ziggit.dev/t/how-to-get-the-current-date-time-and-add-one-hour-to-it/13833/6 "2026-01-08T04:13:56Z")

</div>

i strongly disagree, but then again, i _would,_ being a co-maintainer of the Lua bindings for Zig, wouldn’t I. Like many if not most projects, Ziglua follows master but we tend to rely on PRs and issues to make sure we’re paying attention to when master breaks us.

Zig is a great language for using dependencies, imo. It’s not Rust or Javascript. Typically you can read the code you’re calling into. Your argument against libraries also surely extends to `std` verbatim.

It’s fun to own your whole codebase, to be sure, but it’s also fun to write useful code rather than reinvent the wheel.

---

<div class="post-metadata">

**Author:** ![FObersteiner](https://ziggit.dev/user_avatar/ziggit.dev/fobersteiner/32/1177_2.png) [@FObersteiner](https://ziggit.dev/u/FObersteiner)\
**Post date:** [January 8, 2026, 6:30am UTC](https://ziggit.dev/t/how-to-get-the-current-date-time-and-add-one-hour-to-it/13833/7 "2026-01-08T06:30:18Z")

</div>

related: [State of datetime handling in Zig?](https://ziggit.dev/t/state-of-datetime-handling-in-zig/2149)

> [@saurabh](#):
>
> Another downside is that libraries are likely (and rightly so) at a point release. I’m aiming to be as close to `master` as possible

I’ve took up the task of trying to track Zig master more closely with [FObersteiner/zdt: Datetime, Timezones and Durations in Zig - Codeberg.org](https://codeberg.org/FObersteiner/zdt) recently, and all I can say is this can be a big adventure. Not to depreciate Zig in any way, but you have to know what you’re up to, especially since “documentation” for the most recent changes means “read source and git diffs”.

So in principle, I’m with you on this one. Datetime handling can be so fundamental, you’d want to have it in std. I’m writing this despite having my own third party dt lib 😛 - And years of experience with using Python (dt as part of std, timezone not for a long time - big mess!) and go (dt + timezones as part of std - great!).

* * *

> [@LucasSantos91](#):
>
> the way to do it is

You could also use `std.Io.Clock.real.now(io)`, to get a Timestamp, no need to dive into the vtable.

---

<div class="post-metadata">

**Author:** ![saurabh](https://ziggit.dev/user_avatar/ziggit.dev/saurabh/32/4623_2.png) [@saurabh](https://ziggit.dev/u/saurabh)\
**Post date:** [January 14, 2026, 12:52am UTC](https://ziggit.dev/t/how-to-get-the-current-date-time-and-add-one-hour-to-it/13833/8 "2026-01-14T00:52:59Z")

</div>

> You could also use `std.Io.Clock.real.now(io)`, to get a Timestamp, no need to dive into the vtable.

This fits in well with the another post today [Simple timestamp lib to record timestamp in logs with millisecond precision](https://ziggit.dev/t/simple-timestamp-lib-to-record-timestamp-in-logs-with-millisecond-precision/13658) (and another linked post in it [Format timestamp into ISO 8601 strings](https://ziggit.dev/t/format-timestamp-into-iso-8601-strings/3824)).

> i strongly disagree, but then again, i _would,_ being a co-maintainer of the Lua bindings for Zig, wouldn’t I. Like many if not most projects, Ziglua follows master but we tend to rely on PRs and issues to make sure we’re paying attention to when master breaks us.

Nothing against libraries, but I wish there are more applications with concrete use cases **and** are as visible as their corresponding libraries.  
I would look at those applications and see how I can incorporate them to my use case. After I get my project working it may suck, but I can work towards giving it the functionality of a library or an application which has all the bells and whistles, i.e., there’s scope for craft.

Dependencies have a way of creeping in - in the beginning its going to be just one library, after a while another, and so on. If I take this approach, I will have essentially thrown in the towel at some stage, and be left duct taping dependencies to have a project working. This reflects poorly on me because I didn’t end up doing much and what I did doesn’t look good.

> It’s fun to own your whole codebase, to be sure, but it’s also fun to write useful code rather than reinvent the wheel.

I’m not using datetime yet so I’ll give a different example - CLI. All popular libraries existed before I began working on my projects. I’m using the below features of the standard library:

`ArgIterator` and `while` loop to go through command line arguments, `StaticStringMap` and `enum` to “register” actions, and a `struct` containing `switch`, `if`, and `else` to parse and validate them.  
I could have used a library, but glad I didn’t because I really enjoyed taking this approach. Even if its not as good as using a library, I’d use the standard library ten times out of ten.

No reinvention here and I also dont think approaching datetime using the above linked posts is reinvention.

> Your argument against libraries also surely extends to `std` verbatim.

100%. My projects will never have a dependency other than the standard library. They may end up being verbose but thats fine. I hope `std` remains juicy like main 🙂

---

<div class="post-metadata">

**Author:** ![ehrktia](https://ziggit.dev/user_avatar/ziggit.dev/ehrktia/32/5468_2.png) [@ehrktia](https://ziggit.dev/u/ehrktia)\
**Post date:** [January 14, 2026, 7:55am UTC](https://ziggit.dev/t/how-to-get-the-current-date-time-and-add-one-hour-to-it/13833/9 "2026-01-14T07:55:32Z")

</div>

> [@saurabh](#):
>
> You could also use `std.Io.Clock.real.now(io)`, to get a Timestamp, no need to dive into the vtable.

Thanks for pointing out the lib I did was pre Io refactor (0.16) two weeks ago the initial version will use the Io implementation if one available

---

<div class="post-metadata">

**Author:** ![jumpnbrownweasel](https://ziggit.dev/user_avatar/ziggit.dev/jumpnbrownweasel/32/263_2.png) [@jumpnbrownweasel](https://ziggit.dev/u/jumpnbrownweasel)\
**Post date:** [January 15, 2026, 7:47pm UTC](https://ziggit.dev/t/how-to-get-the-current-date-time-and-add-one-hour-to-it/13833/10 "2026-01-15T19:47:33Z")

</div>

> [@saurabh](#):
>
> Dependencies have a way of creeping in - in the beginning its going to be just one library, after a while another, and so on

They don’t creep, you invite them in each time. Inviting one of them in doesn’t mean you can’t stop inviting more of them.

> [@saurabh](#):
>
> > Your argument against libraries also surely extends to `std` verbatim.
> 
> 100%. My projects will never have a dependency other than the standard library. They may end up being verbose but thats fine. I hope `std` remains juicy like main 🙂

They meant that your rejection of libraries means that you should also reject the std library.

---

<div class="post-metadata">

**Author:** ![saurabh](https://ziggit.dev/user_avatar/ziggit.dev/saurabh/32/4623_2.png) [@saurabh](https://ziggit.dev/u/saurabh)\
**Post date:** [January 15, 2026, 10:53pm UTC](https://ziggit.dev/t/how-to-get-the-current-date-time-and-add-one-hour-to-it/13833/11 "2026-01-15T22:53:44Z")

</div>

> They don’t creep, you invite them in each time. Inviting one of them in doesn’t mean you can’t stop inviting more of them.

Correct, I’ve mentioned that no external dependency will end up in any of my projects for this reason.

> They meant that your rejection of libraries means that you should also reject the std library.

Misunderstood it. I just want to reject external libraries, not the standard library.

---

<div class="post-metadata">

**Author:** ![jumpnbrownweasel](https://ziggit.dev/user_avatar/ziggit.dev/jumpnbrownweasel/32/263_2.png) [@jumpnbrownweasel](https://ziggit.dev/u/jumpnbrownweasel)\
**Post date:** [January 15, 2026, 11:02pm UTC](https://ziggit.dev/t/how-to-get-the-current-date-time-and-add-one-hour-to-it/13833/12 "2026-01-15T23:02:58Z")

</div>

> [@saurabh](#):
>
> > They don’t creep, you invite them in each time. Inviting one of them in doesn’t mean you can’t stop inviting more of them.
> 
> Correct, I’ve mentioned that no external dependency will end up in any of my projects for this reason.

Sorry, I think there is a language problem and I should not have used a double negative. What I meant to say is: You do not have to keep adding dependencies. If you find one great library that you really need, perhaps that will be your only dependency. There is no reason to be rigid on this. But I accept your decision.

---

<div class="post-metadata">

**Author:** ![FObersteiner](https://ziggit.dev/user_avatar/ziggit.dev/fobersteiner/32/1177_2.png) [@FObersteiner](https://ziggit.dev/u/FObersteiner)\
**Post date:** [January 16, 2026, 7:40am UTC](https://ziggit.dev/t/how-to-get-the-current-date-time-and-add-one-hour-to-it/13833/13 "2026-01-16T07:40:18Z")

</div>

> [@jumpnbrownweasel](#):
>
> your rejection of libraries means that you should also reject the std library.

there still is a difference between depending on std and 3rd party libraries, especially in a Zig-context. If you only depend on std, it’s only _your_ code you need to adjust to changes in std. If you depend on 3rd party libs that also depend on std, you rely on them being updated as well. Then again, there are nuances to this; in the open source domain, you might fork the dependency, contribute to it or copy relevant parts to your own code (assuming proper attribution / licensing allows this). So making this a black/white thing won’t help I think. See what works best for your project and decide.

---

<div class="post-metadata">

**Author:** ![miagi](https://ziggit.dev/user_avatar/ziggit.dev/miagi/32/6745_2.png) [@miagi](https://ziggit.dev/u/miagi)\
**Post date:** [January 16, 2026, 9:42am UTC](https://ziggit.dev/t/how-to-get-the-current-date-time-and-add-one-hour-to-it/13833/14 "2026-01-16T09:42:39Z")

</div>

I agree with this.  
In 0.15.2 there is a `directory.walker()` function that I could use in my code, but ended up writing my own recursive function because of all unnecessary functionality the `walker()` was having that I did not need. For that particular use case, my recursive function ended up being more efficient.
