pub struct UtcDateTime(/* private fields */);Expand description
An instant in UTC with nanosecond precision.
Implementations§
Source§impl UtcDateTime
impl UtcDateTime
Sourcepub const UNIX_EPOCH: Self
pub const UNIX_EPOCH: Self
1970-01-01T00:00:00Z.
Sourcepub fn with_ymd_and_hms(
year: i32,
month: u32,
day: u32,
hour: u32,
minute: u32,
second: u32,
) -> Option<Self>
pub fn with_ymd_and_hms( year: i32, month: u32, day: u32, hour: u32, minute: u32, second: u32, ) -> Option<Self>
A UTC calendar date and time; None when a field is out of range.
Sourcepub fn from_timestamp(secs: i64, nanos: u32) -> Option<Self>
pub fn from_timestamp(secs: i64, nanos: u32) -> Option<Self>
From whole seconds since the epoch plus a nanosecond part below one
second. None outside jiff’s range (years -9999 to 9999).
Sourcepub fn from_timestamp_millis(millis: i64) -> Option<Self>
pub fn from_timestamp_millis(millis: i64) -> Option<Self>
From milliseconds since the epoch.
Sourcepub fn from_timestamp_micros(micros: i64) -> Option<Self>
pub fn from_timestamp_micros(micros: i64) -> Option<Self>
From microseconds since the epoch.
Sourcepub fn from_timestamp_nanos(nanos: i64) -> Self
pub fn from_timestamp_nanos(nanos: i64) -> Self
From nanoseconds since the epoch. Every i64 is in range.
Sourcepub fn timestamp(self) -> i64
pub fn timestamp(self) -> i64
Whole seconds since the epoch, rounded towards negative infinity.
Sourcepub fn timestamp_millis(self) -> i64
pub fn timestamp_millis(self) -> i64
Milliseconds since the epoch, rounded towards negative infinity.
Sourcepub fn timestamp_micros(self) -> i64
pub fn timestamp_micros(self) -> i64
Microseconds since the epoch, rounded towards negative infinity.
Sourcepub fn timestamp_nanos_opt(self) -> Option<i64>
pub fn timestamp_nanos_opt(self) -> Option<i64>
Nanoseconds since the epoch, None past the i64 range (year 2262).
Sourcepub fn timestamp_subsec_nanos(self) -> u32
pub fn timestamp_subsec_nanos(self) -> u32
The nanoseconds past UtcDateTime::timestamp, 0..1_000_000_000.
Sourcepub fn timestamp_subsec_millis(self) -> u32
pub fn timestamp_subsec_millis(self) -> u32
The milliseconds past UtcDateTime::timestamp, 0..1000.
Sourcepub fn timestamp_subsec_micros(self) -> u32
pub fn timestamp_subsec_micros(self) -> u32
The microseconds past UtcDateTime::timestamp, 0..1_000_000.
Sourcepub fn parse_from_rfc3339(s: &str) -> Result<Self, ParseError>
pub fn parse_from_rfc3339(s: &str) -> Result<Self, ParseError>
Strict RFC 3339 (2026-11-17T10:00:00Z, …00.5+01:00), converted to
UTC. T, t or a space separates date and time; seconds are
required; the offset is Z, z or ±hh:mm.
Sourcepub fn parse_from_str(s: &str, fmt: &str) -> Result<Self, ParseError>
pub fn parse_from_str(s: &str, fmt: &str) -> Result<Self, ParseError>
Parses s with a strftime pattern that includes an offset (%z,
%:z) or an instant (%s), converted to UTC.
Sourcepub fn to_rfc3339(self) -> String
pub fn to_rfc3339(self) -> String
RFC 3339 with +00:00 and 0, 3, 6 or 9 fractional digits.
Sourcepub fn to_rfc3339_opts(self, secform: SecondsFormat, use_z: bool) -> String
pub fn to_rfc3339_opts(self, secform: SecondsFormat, use_z: bool) -> String
RFC 3339 with the given precision (truncated, never rounded); use_z
writes Z instead of +00:00.
Sourcepub fn format(self, fmt: &str) -> Formatted<'_>
pub fn format(self, fmt: &str) -> Formatted<'_>
strftime; see format for the supported specifiers.
Sourcepub fn date_naive(self) -> Date
pub fn date_naive(self) -> Date
The UTC calendar date.
Sourcepub fn weekday_from_monday(self) -> u32
pub fn weekday_from_monday(self) -> u32
Monday = 0 … Sunday = 6, in UTC.
Sourcepub fn to_local(self) -> LocalDateTime
pub fn to_local(self) -> LocalDateTime
The same instant in the system time zone.
Sourcepub const fn fixed_offset(self) -> OffsetDateTime
pub const fn fixed_offset(self) -> OffsetDateTime
The same instant with offset +00:00.
Sourcepub fn with_offset_seconds(self, secs: i32) -> Option<OffsetDateTime>
pub fn with_offset_seconds(self, secs: i32) -> Option<OffsetDateTime>
The same instant shown secs east of UTC; None unless
|secs| < 86_400 (chrono’s FixedOffset::east_opt range).
Sourcepub fn duration_trunc(self, span: Duration) -> Result<Self, OutOfRangeError>
pub fn duration_trunc(self, span: Duration) -> Result<Self, OutOfRangeError>
Rounded down to a whole multiple of span since the Unix epoch, like
chrono’s DurationRound::duration_trunc: an error for a span that is
not positive or longer than the time since the epoch.
Sourcepub fn with_nanosecond(self, nano: u32) -> Option<Self>
pub fn with_nanosecond(self, nano: u32) -> Option<Self>
The same second with the fraction set to nano; None for
nano >= 1_000_000_000 (chrono’s leap-second range is not kept).
Sourcepub const fn to_utc(self) -> Self
pub const fn to_utc(self) -> Self
Itself: the counterpart of OffsetDateTime::to_utc and
LocalDateTime::to_utc, so code generic over the source reads alike.
Sourcepub fn signed_duration_since(self, other: impl Into<UtcDateTime>) -> Duration
pub fn signed_duration_since(self, other: impl Into<UtcDateTime>) -> Duration
self - other.
Sourcepub fn checked_add_signed(self, d: Duration) -> Option<Self>
pub fn checked_add_signed(self, d: Duration) -> Option<Self>
self + d, None outside the representable range.
Sourcepub fn checked_sub_signed(self, d: Duration) -> Option<Self>
pub fn checked_sub_signed(self, d: Duration) -> Option<Self>
self - d, None outside the representable range.
Sourcepub fn trunc_subsecs_to_secs(self) -> Self
pub fn trunc_subsecs_to_secs(self) -> Self
The instant truncated to whole seconds (towards the past).
Sourcepub fn to_system_time(self) -> SystemTime
pub fn to_system_time(self) -> SystemTime
The instant as a SystemTime.
Trait Implementations§
Source§impl Add<Duration> for UtcDateTime
impl Add<Duration> for UtcDateTime
Source§impl Add<Duration> for UtcDateTime
impl Add<Duration> for UtcDateTime
Source§impl AddAssign<Duration> for UtcDateTime
impl AddAssign<Duration> for UtcDateTime
Source§fn add_assign(&mut self, d: Duration)
fn add_assign(&mut self, d: Duration)
+= operation. Read moreSource§impl Clone for UtcDateTime
impl Clone for UtcDateTime
impl Copy for UtcDateTime
Source§impl Debug for UtcDateTime
impl Debug for UtcDateTime
Source§impl<'de> Deserialize<'de> for UtcDateTime
impl<'de> Deserialize<'de> for UtcDateTime
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Source§impl Display for UtcDateTime
impl Display for UtcDateTime
impl Eq for UtcDateTime
Source§impl From<OffsetDateTime> for UtcDateTime
impl From<OffsetDateTime> for UtcDateTime
Source§fn from(t: OffsetDateTime) -> Self
fn from(t: OffsetDateTime) -> Self
Source§impl From<SystemTime> for UtcDateTime
impl From<SystemTime> for UtcDateTime
Source§fn from(t: SystemTime) -> Self
fn from(t: SystemTime) -> Self
Panics outside jiff’s range (years -9999 to 9999), as chrono’s conversion does outside its own.
Source§impl From<Timestamp> for UtcDateTime
impl From<Timestamp> for UtcDateTime
Source§impl From<UtcDateTime> for SystemTime
impl From<UtcDateTime> for SystemTime
Source§fn from(t: UtcDateTime) -> Self
fn from(t: UtcDateTime) -> Self
Source§impl From<UtcDateTime> for Timestamp
impl From<UtcDateTime> for Timestamp
Source§fn from(t: UtcDateTime) -> Self
fn from(t: UtcDateTime) -> Self
Source§impl FromStr for UtcDateTime
impl FromStr for UtcDateTime
Source§type Err = ParseError
type Err = ParseError
Source§impl Hash for UtcDateTime
impl Hash for UtcDateTime
Source§impl Ord for UtcDateTime
impl Ord for UtcDateTime
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.21.0 (const: unstable) · Source§fn min(self, other: Self) -> Selfwhere
Self: Sized,
fn min(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialEq for UtcDateTime
impl PartialEq for UtcDateTime
Source§impl PartialEq<OffsetDateTime> for UtcDateTime
impl PartialEq<OffsetDateTime> for UtcDateTime
Source§impl PartialEq<UtcDateTime> for OffsetDateTime
impl PartialEq<UtcDateTime> for OffsetDateTime
Source§impl PartialOrd for UtcDateTime
impl PartialOrd for UtcDateTime
Source§impl PartialOrd<OffsetDateTime> for UtcDateTime
impl PartialOrd<OffsetDateTime> for UtcDateTime
Source§impl PartialOrd<UtcDateTime> for OffsetDateTime
impl PartialOrd<UtcDateTime> for OffsetDateTime
Source§impl Serialize for UtcDateTime
impl Serialize for UtcDateTime
impl StructuralPartialEq for UtcDateTime
Source§impl Sub for UtcDateTime
impl Sub for UtcDateTime
Source§impl Sub<Duration> for UtcDateTime
impl Sub<Duration> for UtcDateTime
Source§impl Sub<Duration> for UtcDateTime
impl Sub<Duration> for UtcDateTime
Source§impl Sub<OffsetDateTime> for UtcDateTime
impl Sub<OffsetDateTime> for UtcDateTime
Source§impl Sub<UtcDateTime> for OffsetDateTime
impl Sub<UtcDateTime> for OffsetDateTime
Source§impl SubAssign<Duration> for UtcDateTime
impl SubAssign<Duration> for UtcDateTime
Source§fn sub_assign(&mut self, d: Duration)
fn sub_assign(&mut self, d: Duration)
-= operation. Read more