rsimple_date
PHP-style date() formatting for Rust.
If you know date("Y-m-d H:i:s") from PHP, you can use the same format tokens in Rust — no need to learn Chrono’s strftime-style %Y-%m-%d %H:%M:%S for everyday formatting.
Chrono is used internally and is not part of this crate’s public API.
Quick start
[]
= "0.1"
use ;
API
| Function | PHP analog | Description |
|---|---|---|
date(format) |
date($format) |
Format current local time |
date_with(format, ts) |
date($format, $ts) |
Format Unix timestamp in local TZ |
gmdate(format) |
gmdate($format) |
Format current UTC time |
gmdate_with(format, ts) |
gmdate($format, $ts) |
Format Unix timestamp in UTC |
time() |
time() |
Current Unix timestamp (seconds) |
Also exports PHP-style constants such as DATE_ATOM, DATE_RFC2822, DATE_RSS, …
Format tokens
Supports the common PHP DateTimeInterface::format characters, including:
- Date:
YymndjFMDlNwzWtLoS - Time:
HGhgisaABuv - TZ:
eIOPpTZ(best-effort without a TZ database) - Full:
crU - Escape:
\Xprints literalX
Unrecognized characters are copied through as literals (PHP behavior).
Limitations
- Chrono is an internal dependency; you do not import or learn Chrono to use this crate.
- Offset tokens (
O,P,p,Z) reflect the real UTC offset. - Without an IANA timezone database,
e/Tare best-effort ("UTC"or an offset string), andI(DST) is always"0". - Extremely out-of-range Unix timestamps are clamped to the Unix epoch so formatting never panics.
License
Licensed under either of
- Apache License, Version 2.0
- MIT license
at your option.