Sample code for 30+ languages & platforms
Zig

MIME CurrentDateTime Property

See more MIME Examples

Demonstrates the read-only CurrentDateTime property, which returns the current local date and time formatted as an Internet message date including the numeric UTC offset. The example uses it to populate a Date header field.

Background. Internet message dates follow the RFC 5322 format, for example Fri, 21 Nov 1997 09:55:06 -0600. CurrentDateTime produces a value in that form for use in message headers.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    const mime = try chilkat.Mime.init();
    defer mime.deinit();
    mime.setBodyFromPlainText("Message with a Date header.") catch {
        std.debug.print("{s}\n", .{try mime.getLastErrorText(alloc)});
        return;
    };

    // CurrentDateTime returns the current local date and time formatted as an Internet message date,
    // including the numeric UTC offset, for example: Fri, 21 Nov 1997 09:55:06 -0600
    const now = try mime.getCurrentDateTime(alloc);
    std.debug.print("Current date/time: {s}\n", .{now});

    // It can be used to populate a Date header field.
    mime.setHeaderField("Date", now) catch {};

    const head = mime.getEntireHead(alloc) catch {
        std.debug.print("{s}\n", .{try mime.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("{s}\n", .{head});
}