Skip to main content

Crate rsimple_date

Crate rsimple_date 

Source
Expand description

PHP-style date() formatting for Rust.

Format dates with familiar PHP tokens instead of strftime-style %Y-%m-%d:

use rsimple_date::{date, gmdate_with};

let now = date("Y-m-d H:i:s");
assert_eq!(now.len(), 19);

assert_eq!(gmdate_with("Y-m-d", 978307200), "2001-01-01");

§Features

  • PHP date() / gmdate() / time() style API
  • Familiar tokens such as Y-m-d H:i:s, c, r, and escapes like \T
  • Predefined format constants (DATE_ATOM, DATE_RFC2822, …)

Chrono is used internally and is not part of the public API.

§Timezone limitations

Offset tokens (O, P, p, Z) are accurate. Identifier / DST tokens (e, T, I) are best-effort without an IANA timezone database: I is always "0", and e/T report "UTC" or an offset string.

Constants§

DATE_ATOM
Atom (example: 2005-08-15T15:52:01+00:00)
DATE_COOKIE
HTTP Cookies (example: Monday, 15-Aug-2005 15:52:01 UTC)
DATE_ISO8601
ISO-8601 (example: 2005-08-15T15:52:01+0000)
DATE_RFC822
RFC 822 (example: Mon, 15 Aug 05 15:52:01 +0000)
DATE_RFC850
RFC 850 (example: Monday, 15-Aug-05 15:52:01 UTC)
DATE_RFC1036
RFC 1036 (example: Mon, 15 Aug 05 15:52:01 +0000)
DATE_RFC1123
RFC 1123 (example: Mon, 15 Aug 2005 15:52:01 +0000)
DATE_RFC2822
RFC 2822 (example: Mon, 15 Aug 2005 15:52:01 +0000)
DATE_RFC3339
RFC 3339 (example: 2005-08-15T15:52:01+00:00)
DATE_RFC3339_EXTENDED
RFC 3339 EXTENDED (example: 2005-08-15T15:52:01.000+00:00)
DATE_RSS
RSS (example: Mon, 15 Aug 2005 15:52:01 +0000)
DATE_W3C
World Wide Web Consortium (example: 2005-08-15T15:52:01+00:00)

Functions§

date
Format the current local time with a PHP format string (PHP date($format)).
date_with
Format a Unix timestamp in the local timezone (PHP date($format, $timestamp)).
gmdate
Format the current UTC time (PHP gmdate($format)).
gmdate_with
Format a Unix timestamp in UTC (PHP gmdate($format, $timestamp)).
time
Return the current Unix timestamp in seconds (PHP time()).