Crate time[][src]

Expand description

GitHub time-rs/time license MIT or Apache-2.0 minimum rustc 1.32.0

Feature flags

This crate exposes a number of features. These can be enabled or disabled as shown in Cargo’s documentation. Features are disabled by default unless otherwise noted.

Reliance on a given feature is always indicated alongside the item definition.

  • std (enabled by default)

    This enables a number of features that depend on the standard library. Instant is the primary item that requires this feature, though some others methods may rely on Instant internally.

    This crate currently requires a global allocator be present even if this feature is disabled.

  • serde

    Enables serde support for all types.

  • rand

    Enables rand support for all types.

  • deprecated (enabled by default)

    Allows using certain deprecated functions from time 0.1.

  • panicking-api

    Non-panicking APIs are provided, and should generally be preferred. However, there are some situations where avoiding .unwrap() may be desired. Generally speaking, macros should be used in these situations. Library authors should avoid using this feature.

Formatting

Time’s formatting behavior is based on strftime in C, though it is explicitly not compatible. Specifiers may be missing, added, or have different behavior than in C. As such, you should use the table below, which is an up-to-date reference on what each specifier does.

Specifiers
SpecifierReplaced byExample
%aAbbreviated weekday nameThu
%AFull weekday nameThursday
%bAbbreviated month nameAug
%BFull month nameAugust
%cDate and time representation, equivalent to %a %b %-d %-H:%M:%S %-YThu Aug 23 14:55:02 2001
%CYear divided by 100 and truncated to integer (00-999)20
%dDay of the month, zero-padded (01-31)23
%DShort MM/DD/YY date, equivalent to %-m/%d/%y8/23/01
%FShort YYYY-MM-DD date, equivalent to %-Y-%m-%d2001-08-23
%gWeek-based year, last two digits (00-99)01
%GWeek-based year2001
%HHour in 24h format (00-23)14
%IHour in 12h format (01-12)02
%jDay of the year (001-366)235
%mMonth as a decimal number (01-12)08
%MMinute (00-59)55
%NSubsecond nanoseconds. Always 9 digits012345678
%pam or pm designationpm
%PAM or PM designationPM
%r12-hour clock time, equivalent to %-I:%M:%S %p2:55:02 pm
%R24-hour HH:MM time, equivalent to %-H:%M14:55
%SSecond (00-59)02
%T24-hour clock time with seconds, equivalent to %-H:%M:%S14:55:02
%uISO 8601 weekday as number with Monday as 1 (1-7)4
%UWeek number with the first Sunday as the start of week one (00-53)33
%VISO 8601 week number (01-53)34
%wWeekday as a decimal number with Sunday as 0 (0-6)4
%WWeek number with the first Monday as the start of week one (00-53)34
%yYear, last two digits (00-99)01
%YFull year, including + if ≥10,0002001
%zISO 8601 offset from UTC in timezone (+HHMM)+0100
%%Literal %%

Modifiers

All specifiers that are strictly numerical have modifiers for formatting. Adding a modifier to a non-supporting specifier is a no-op.

ModifierBehaviorExample
- (dash)No padding%-d => 5
_ (underscore)Pad with spaces%_d => 5
0Pad with zeros%0d => 05

Re-exports

pub use error::Error;
pub use error::ComponentRange as ComponentRangeError;
pub use error::ConversionRange as ConversionRangeError;
pub use error::IndeterminateOffset as IndeterminateOffsetError;
pub use ext::NumericalDuration;
pub use ext::NumericalStdDuration;
pub use util::days_in_year;
pub use util::is_leap_year;
pub use util::validate_format_string;
pub use util::weeks_in_year;

Modules

Various error types returned by methods in the time crate.

Extension traits.

Macros to statically construct values that are known to be valid.

A collection of imports that are widely useful.

Utility functions.

Macros

Structs

Calendar date.

A span of time with nanosecond precision.

A measurement of a monotonically non-decreasing clock. Opaque and useful only with Duration.

Combined date and time.

The clock time within a given date. Nanosecond precision.

An offset from UTC.

Enums

Various well-known formats, along with the possibility for a custom format (provided either at compile-time or runtime).

An error occurred while parsing.

SignDeprecated

Contains the sign of a value: positive, negative, or zero.

Days of the week.

Functions

Parse any parsable type from the time crate.

precise_time_nsDeprecated
precise_time_sDeprecated

Type Definitions

PreciseTimeDeprecated

An alias for Result with a generic error from the time crate.

SteadyTimeDeprecated