now-time
Get the current UTC or local time with zero boilerplate.
Overview
now-time gives you the current time in one line. No setup, no config, no boilerplate.
Two dependencies: chrono for the time primitives, thiserror for errors. Everything else is stdlib.
Install
[]
= "1.0.3"
Usage
Quick functions
use ;
println!; // 2024-11-15T10:30:00.000000000+00:00
println!; // 2024-11-15T18:30:00.000000000+08:00
println!; // 1731664200
println!; // 1731664200123
Full API
use TimeSnapshot;
let t = now_utc;
println!; // ISO 8601 UTC
println!; // ISO 8601 with local offset
println!; // email / HTTP header style
println!; // 1731664200
println!; // 1731664200123
println!; // 2024-11-15 10:30:00
Custom format
Uses chrono's strftime specifiers:
| Spec | Meaning | Example |
|---|---|---|
%Y |
4-digit year | 2024 |
%m |
month (01-12) | 11 |
%d |
day (01-31) | 15 |
%H |
hour (00-23) | 10 |
%M |
minute (00-59) | 30 |
%S |
second (00-59) | 00 |
Full list: https://docs.rs/chrono/latest/chrono/format/strftime
API Reference
| Function / Method | Returns | Description |
|---|---|---|
now_utc() |
TimeSnapshot |
Current time in UTC |
now_local() |
TimeSnapshot |
Current time in local timezone |
unix_timestamp() |
i64 |
Unix timestamp in seconds |
unix_timestamp_millis() |
i64 |
Unix timestamp in milliseconds |
TimeSnapshot::to_rfc3339() |
String |
ISO 8601 UTC string |
TimeSnapshot::to_local_rfc3339() |
String |
ISO 8601 with local offset |
TimeSnapshot::to_rfc2822() |
String |
RFC 2822 string |
TimeSnapshot::unix_seconds() |
i64 |
Seconds since Unix epoch |
TimeSnapshot::unix_millis() |
i64 |
Milliseconds since Unix epoch |
TimeSnapshot::format(pattern) |
String |
Custom strftime format |
TimeSnapshot::as_datetime() |
&DateTime<Utc> |
Raw chrono DateTime |
License
MIT. See LICENSE.