A date and time parse and format library for Zig.
- Zig >= 0.16.0
Add the dependency to your project:
zig fetch --save=zig-time git+https://github.com/deatil/zig-time#mainor use local path to add dependency at build.zig.zon file
.{
.dependencies= .{
.@"zig-time"= .{
.path="./lib/zig-time",
},
...
},
...
}And the following to your build.zig file:
constzig_time_dep=b.dependency("zig-time", .{});
exe.root_module.addImport("zig-time", zig_time_dep.module("zig-time"));The zig-time structure can be imported in your application with:
constzig_time=@import("zig-time");conststd=@import("std");
consttime=@import("zig-time");
pubfnmain(init: std.process.Init) !void {
constio=init.io;
consttime_0=time.now(io).timestamp();
std.debug.print("now time: {d} \n", .{time_0});
// ==========constseed: i64=1691879007;
constfmt: []constu8="YYYY-MM-DD HH:mm:ss z";
constalloc=std.heap.page_allocator;
constinstant=time.Time.fromTimestamp(seed).setLoc(time.UTC);
constfmtRes=tryinstant.formatAlloc(alloc, fmt);
deferalloc.free(fmtRes);
// output: // format time: 2023-08-12 22:23:27 UTCstd.debug.print("format time: {s} \n", .{fmtRes});
}- The library LICENSE is
Apache2, using the library need keep the LICENSE.
- Copyright deatil(https://github.com/deatil).