11 releases (6 stable)

1.3.1 Oct 17, 2024
1.3.0 Oct 1, 2024
1.2.0 Jul 23, 2024
1.0.0 May 16, 2024
0.1.3 Apr 16, 2024

#224 in Date and time

Download history 355/week @ 2024-07-26 341/week @ 2024-08-02 287/week @ 2024-08-09 86/week @ 2024-08-16 196/week @ 2024-08-23 131/week @ 2024-08-30 290/week @ 2024-09-06 55/week @ 2024-09-13 66/week @ 2024-09-20 218/week @ 2024-09-27 88/week @ 2024-10-04 282/week @ 2024-10-11 126/week @ 2024-10-18 16/week @ 2024-10-25 26/week @ 2024-11-01 22/week @ 2024-11-08

318 downloads per month

MIT license

39KB
928 lines

Date & Time

ci codecov release docs

The datetime crate provides a simple, easy-to-use DateTime struct (and corresponding macro). DateTime provides storage for a date and time, and optionally a time zone (if the tz feature is enabled).

The underlying storage is a Unix timestamp, so DateTime objects are comparable (even when in different time zones). Additonally, if you don't need the concept of time zones (e.g. because you can assume one), you can leave the tz feature off and not take the baggage.

A DateTime with no time zone specified behaves identically to UTC.

Examples

Making a DateTime:

use datetime::DateTime;

let dt = DateTime::ymd(2012, 4, 21).hms(11, 0, 0).build();

You can also use the datetime! macro to get a syntax resembling a date literal:

use datetime::datetime;

let dt = datetime! { 2012-04-21 11:00:00 };

Features

datetime-rs ships with the following features:

  • diesel-pg: Enables interop with PostgreSQL TIMESTAMP columns using Diesel.
  • serde: Enables serialization and desearialization with serde. (Enabled by default.)
  • tz: Enables support for time-zone-aware date construction.

Dependencies

~0.2–1.4MB
~27K SLoC