Crate time[−][src]
Expand description
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 onInstant
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
Specifier | Replaced by | Example |
---|---|---|
%a | Abbreviated weekday name | Thu |
%A | Full weekday name | Thursday |
%b | Abbreviated month name | Aug |
%B | Full month name | August |
%c | Date and time representation, equivalent to %a %b %-d %-H:%M:%S %-Y | Thu Aug 23 14:55:02 2001 |
%C | Year divided by 100 and truncated to integer (00 -999 ) | 20 |
%d | Day of the month, zero-padded (01 -31 ) | 23 |
%D | Short MM/DD/YY date, equivalent to %-m/%d/%y | 8/23/01 |
%F | Short YYYY-MM-DD date, equivalent to %-Y-%m-%d | 2001-08-23 |
%g | Week-based year, last two digits (00 -99 ) | 01 |
%G | Week-based year | 2001 |
%H | Hour in 24h format (00 -23 ) | 14 |
%I | Hour in 12h format (01 -12 ) | 02 |
%j | Day of the year (001 -366 ) | 235 |
%m | Month as a decimal number (01 -12 ) | 08 |
%M | Minute (00 -59 ) | 55 |
%N | Subsecond nanoseconds. Always 9 digits | 012345678 |
%p | am or pm designation | pm |
%P | AM or PM designation | PM |
%r | 12-hour clock time, equivalent to %-I:%M:%S %p | 2:55:02 pm |
%R | 24-hour HH:MM time, equivalent to %-H:%M | 14:55 |
%S | Second (00 -59 ) | 02 |
%T | 24-hour clock time with seconds, equivalent to %-H:%M:%S | 14:55:02 |
%u | ISO 8601 weekday as number with Monday as 1 (1 -7 ) | 4 |
%U | Week number with the first Sunday as the start of week one (00 -53 ) | 33 |
%V | ISO 8601 week number (01 -53 ) | 34 |
%w | Weekday as a decimal number with Sunday as 0 (0 -6 ) | 4 |
%W | Week number with the first Monday as the start of week one (00 -53 ) | 34 |
%y | Year, last two digits (00 -99 ) | 01 |
%Y | Full year, including + if ≥10,000 | 2001 |
%z | ISO 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.
Modifier | Behavior | Example |
---|---|---|
- (dash) | No padding | %-d => 5 |
_ (underscore) | Pad with spaces | %_d => 5 |
0 | Pad 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 ext::NumericalStdDurationShort; | |
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
error | Various error types returned by methods in the time crate. |
ext | Extension traits. |
macros | Macros to statically construct values that are known to be valid. |
prelude | A collection of imports that are widely useful. |
serde | Differential formats for serde. |
util | Utility functions. |
Macros
date | |
offset | |
time |
Structs
Date | Calendar date. |
Duration | A span of time with nanosecond precision. |
Instant | std A measurement of a monotonically non-decreasing clock. Opaque and useful
only with |
OffsetDateTime | A |
PrimitiveDateTime | Combined date and time. |
Time | The clock time within a given date. Nanosecond precision. |
UtcOffset | An offset from UTC. |
Enums
Format | Various well-known formats, along with the possibility for a custom format (provided either at compile-time or runtime). |
ParseError | An error occurred while parsing. |
Sign | Deprecated Contains the sign of a value: positive, negative, or zero. |
Weekday | Days of the week. |
Functions
parse | Parse any parsable type from the time crate. |
precise_time_ns | Deprecated |
precise_time_s | Deprecated |
Type Definitions
PreciseTime | Deprecated |
Result | An alias for |
SteadyTime | Deprecated |