Struct aws_sdk_athena::types::DateTime
source · 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§
source§impl DateTime
impl DateTime
sourcepub fn from_secs(epoch_seconds: i64) -> DateTime
pub fn from_secs(epoch_seconds: i64) -> DateTime
Creates a DateTime
from a number of seconds since the Unix epoch.
sourcepub fn from_millis(epoch_millis: i64) -> DateTime
pub fn from_millis(epoch_millis: i64) -> DateTime
Creates a DateTime
from a number of milliseconds since the Unix epoch.
sourcepub fn from_nanos(epoch_nanos: i128) -> Result<DateTime, ConversionError>
pub fn from_nanos(epoch_nanos: i128) -> Result<DateTime, ConversionError>
Creates a DateTime
from a number of nanoseconds since the Unix epoch.
sourcepub fn as_nanos(&self) -> i128
pub fn as_nanos(&self) -> i128
Returns the number of nanoseconds since the Unix epoch that this DateTime
represents.
sourcepub fn from_fractional_secs(epoch_seconds: i64, fraction: f64) -> DateTime
pub fn from_fractional_secs(epoch_seconds: i64, fraction: f64) -> DateTime
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),
);
sourcepub fn from_secs_and_nanos(seconds: i64, subsecond_nanos: u32) -> DateTime
pub fn from_secs_and_nanos(seconds: i64, subsecond_nanos: u32) -> DateTime
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),
);
sourcepub fn as_secs_f64(&self) -> f64
pub fn as_secs_f64(&self) -> f64
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.
sourcepub fn from_secs_f64(epoch_seconds: f64) -> DateTime
pub fn from_secs_f64(epoch_seconds: f64) -> DateTime
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),
);
sourcepub fn from_str(s: &str, format: Format) -> Result<DateTime, DateTimeParseError>
pub fn from_str(s: &str, format: Format) -> Result<DateTime, DateTimeParseError>
Parses a DateTime
from a string using the given format
.
sourcepub fn has_subsec_nanos(&self) -> bool
pub fn has_subsec_nanos(&self) -> bool
Returns true if sub-second nanos is greater than zero.
sourcepub fn secs(&self) -> i64
pub fn secs(&self) -> i64
Returns the epoch seconds component of the DateTime
.
Note: this does not include the sub-second nanos.
sourcepub fn subsec_nanos(&self) -> u32
pub fn subsec_nanos(&self) -> u32
Returns the sub-second nanos component of the DateTime
.
Note: this does not include the number of seconds since the epoch.
sourcepub fn to_millis(self) -> Result<i64, ConversionError>
pub fn to_millis(self) -> Result<i64, ConversionError>
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.