NIAOJoin Beta
Ecosystem

time

available

Wall-Clock & Time Zones

Core Standard Library

Overview

time is for anything wall-clock related: log timestamps, scheduling, parsing ISO dates from an API. now() gives you the current instant; format and parse use strftime-style patterns.

Timezone conversion goes through IANA names (America/New_York, Asia/Tokyo) with daylight saving rules baked in via chrono-tz. You can add durations, diff two instants, and compare datetimes without rolling your own calendar math.

  • IANA time zones
  • strftime formats
  • Datetime values
  • Date math

Import

import
import "time"

Quick start

quick start
import "time"
let now = time.now()
let formatted = time.format(now, "%Y-%m-%d %H:%M:%S %Z")
let tokyo = time.to_timezone(now, "Asia/Tokyo")

Capabilities

High-level overview of what time is for.

IANA time zones

Convert an instant to another zone by name. DST transitions are handled by the tz database, not hard-coded offsets.

strftime formatting

%Y-%m-%d, %H:%M:%S, %Z, and the usual directives for logs and user-facing dates.

Datetime objects

Construct a specific date/time, read out year/month/day/hour/minute/second, compare two values.

Date arithmetic

Add a duration, measure the gap between two instants, parse ISO-8601 strings from wire formats.

API reference

44 functions and methods in time. Grouped by category from the standard library docs.

Wall clock

SignatureDescription
time.now_unix_ms()Unix epoch milliseconds (wall clock)
time.now_unix_s()Unix epoch seconds
time.now_iso()RFC 3339 string in UTC
time.now_iso_local()RFC 3339 string in local timezone
time.now(tz?)Datetime object (`tz` defaults to `"local"`)

Format & parse

SignatureDescription
time.format(ms, fmt, tz?)Format timestamp (`tz` defaults to `"UTC"`)
time.parse(text, fmt, tz?)Parse string → unix ms (`tz` defaults to `"UTC"`)
time.to_iso(ms, tz?)ISO 8601 with offset

Datetime object

SignatureDescription
yearCalendar year
month1–12
day1–31
hour0–23
minute0–59
second0–59
millisecond0–999
weekday0 = Monday … 6 = Sunday
weekday_namee.g. `"Friday"`
unix_msOriginal timestamp
timezonee.g. `"UTC"`, `"local"`, `"Asia/Kolkata"`
utc_offset_msUTC offset in milliseconds

Construction & decomposition

SignatureDescription
time.from_parts(year, month, day, hour?, minute?, second?, ms?, tz?)Build unix ms from parts (`tz` defaults to `"local"`)
time.decompose(ms, tz?)Split timestamp into datetime object

Arithmetic

SignatureDescription
time.add_ms(ms, delta)Add milliseconds
time.add_seconds(ms, delta)Add seconds
time.add_minutes(ms, delta)Add minutes
time.add_hours(ms, delta)Add hours
time.add_days(ms, delta)Add days
time.diff_ms(a, b)Returns `a - b` in milliseconds

Time zones

SignatureDescription
time.utc_offset_ms(tz, ms?)UTC offset in ms at `ms` (default: now)
time.list_timezones()Sorted list of IANA timezone names

Calendar helpers

SignatureDescription
time.is_leap_year(year)Leap year check
time.days_in_month(year, month)Days in month (1–12)
time.is_valid_date(year, month, day)Valid calendar date
time.start_of_day(ms, tz?)Midnight in timezone
time.end_of_day(ms, tz?)23:59:59.999 in timezone

Components

SignatureDescription
time.year(ms, tz?)Year component
time.month(ms, tz?)Month component
time.day(ms, tz?)Day component
time.hour(ms, tz?)Hour component
time.minute(ms, tz?)Minute component
time.second(ms, tz?)Second component
time.weekday(ms, tz?)Weekday 0–6 (Mon–Sun)
time.weekday_name(ms, tz?)Weekday name

Sleep

SignatureDescription
time.sleep_ms(ms)Block for `ms` milliseconds

Related libraries

More from Core Standard Library.

available

json

JSON Parse & Manipulate

Parse, build, and edit JSON. Backed by serde_json in Rust, nested get/set, merge, and pretty-print included.

  • parse & stringify
  • Dot-path access
  • Deep merge
  • Pretty-print
Read more
available

io

File & Path I/O

Read and write files, stream large inputs, and work with paths. Blocking I/O can run on background threads.

  • Whole-file read/write
  • Streaming handles
  • Background I/O
  • Path helpers
Read more
available

re

Regular Expressions

Regular expressions via Rust's regex crate. Match, split, replace, and compile patterns once for hot loops.

  • Capture groups
  • Search & replace
  • Compiled patterns
  • Unicode-aware
Read more