pub struct DateTime { /* private fields */ }
Expand description

DateTime in time.

DateTime in time represented as seconds and sub-second nanos since the Unix epoch (January 1, 1970 at midnight UTC/GMT).

This type can be converted to/from the standard library’s SystemTime:

use std::convert::TryFrom;

let the_millennium_as_system_time = SystemTime::try_from(DateTime::from_secs(946_713_600))?;
let now_as_date_time = DateTime::from(SystemTime::now());

The aws-smithy-types-convert crate can be used for conversions to/from other libraries, such as time or chrono.

Implementations

Creates a DateTime from a number of seconds since the Unix epoch.

Creates a DateTime from a number of milliseconds since the Unix epoch.

Creates a DateTime from a number of nanoseconds since the Unix epoch.

Returns the number of nanoseconds since the Unix epoch that this DateTime represents.

Creates a DateTime from a number of seconds and a fractional second since the Unix epoch.

Example
assert_eq!(
    DateTime::from_secs_and_nanos(1, 500_000_000u32),
    DateTime::from_fractional_secs(1, 0.5),
);

Creates a DateTime from a number of seconds and sub-second nanos since the Unix epoch.

Example
assert_eq!(
    DateTime::from_fractional_secs(1, 0.5),
    DateTime::from_secs_and_nanos(1, 500_000_000u32),
);

Returns the DateTime value as an f64 representing the seconds since the Unix epoch.

Note: This conversion will lose precision due to the nature of floating point numbers.

Creates a DateTime from an f64 representing the number of seconds since the Unix epoch.

Example
assert_eq!(
    DateTime::from_fractional_secs(1, 0.5),
    DateTime::from_secs_f64(1.5),
);

Parses a DateTime from a string using the given format.

Returns true if sub-second nanos is greater than zero.

Returns the epoch seconds component of the DateTime.

Note: this does not include the sub-second nanos.

Returns the sub-second nanos component of the DateTime.

Note: this does not include the number of seconds since the epoch.

Converts the DateTime to the number of milliseconds since the Unix epoch.

This is fallible since DateTime holds more precision than an i64, and will return a ConversionError for DateTime values that can’t be converted.

Read 1 date of format from s, expecting either delim or EOF

Enable parsing multiple dates from the same string

Formats the DateTime to a string using the given format.

Returns an error if the given DateTime cannot be represented by the desired format.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Tries to convert a DateTime into a SystemTime.

This can fail if the the DateTime value is larger or smaller than what the SystemTime can represent on the operating system it’s compiled for. On Linux, for example, it will only fail on Instant::from_secs(i64::MIN) (with any nanoseconds value). On Windows, however, Rust’s standard library uses a smaller precision type for SystemTime, and it will fail conversion for a much larger range of date-times. This is only an issue if dealing with date-times beyond several thousands of years from now.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.