Skip to main content

UtcDateTime

Struct UtcDateTime 

Source
pub struct UtcDateTime(/* private fields */);
Expand description

An instant in UTC with nanosecond precision.

Implementations§

Source§

impl UtcDateTime

Source

pub const UNIX_EPOCH: Self

1970-01-01T00:00:00Z.

Source

pub fn now() -> Self

The current time from the system clock.

Source

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.

Source

pub const fn from_jiff(ts: Timestamp) -> Self

Wraps a jiff timestamp.

Source

pub const fn as_jiff(self) -> Timestamp

The jiff timestamp underneath.

Source

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).

Source

pub fn from_timestamp_millis(millis: i64) -> Option<Self>

From milliseconds since the epoch.

Source

pub fn from_timestamp_micros(micros: i64) -> Option<Self>

From microseconds since the epoch.

Source

pub fn from_timestamp_nanos(nanos: i64) -> Self

From nanoseconds since the epoch. Every i64 is in range.

Source

pub fn timestamp(self) -> i64

Whole seconds since the epoch, rounded towards negative infinity.

Source

pub fn timestamp_millis(self) -> i64

Milliseconds since the epoch, rounded towards negative infinity.

Source

pub fn timestamp_micros(self) -> i64

Microseconds since the epoch, rounded towards negative infinity.

Source

pub fn timestamp_nanos_opt(self) -> Option<i64>

Nanoseconds since the epoch, None past the i64 range (year 2262).

Source

pub fn timestamp_subsec_nanos(self) -> u32

The nanoseconds past UtcDateTime::timestamp, 0..1_000_000_000.

Source

pub fn timestamp_subsec_millis(self) -> u32

The milliseconds past UtcDateTime::timestamp, 0..1000.

Source

pub fn timestamp_subsec_micros(self) -> u32

The microseconds past UtcDateTime::timestamp, 0..1_000_000.

Source

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.

Source

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.

Source

pub fn to_rfc3339(self) -> String

RFC 3339 with +00:00 and 0, 3, 6 or 9 fractional digits.

Source

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.

Source

pub fn format(self, fmt: &str) -> Formatted<'_>

strftime; see format for the supported specifiers.

Source

pub fn date_naive(self) -> Date

The UTC calendar date.

Source

pub fn naive_utc(self) -> DateTime

The UTC calendar date and wall time.

Source

pub fn year(self) -> i32

The year in UTC.

Source

pub fn month(self) -> u32

The month in UTC, 1..=12.

Source

pub fn day(self) -> u32

The day of the month in UTC, 1..=31.

Source

pub fn hour(self) -> u32

The hour in UTC, 0..=23.

Source

pub fn minute(self) -> u32

The minute in UTC, 0..=59.

Source

pub fn second(self) -> u32

The second in UTC, 0..=59.

Source

pub fn ordinal(self) -> u32

The day of the year in UTC, 1..=366.

Source

pub fn weekday_from_monday(self) -> u32

Monday = 0 … Sunday = 6, in UTC.

Source

pub fn to_local(self) -> LocalDateTime

The same instant in the system time zone.

Source

pub const fn fixed_offset(self) -> OffsetDateTime

The same instant with offset +00:00.

Source

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).

Source

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.

Source

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).

Source

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.

Source

pub fn signed_duration_since(self, other: impl Into<UtcDateTime>) -> Duration

self - other.

Source

pub fn checked_add_signed(self, d: Duration) -> Option<Self>

self + d, None outside the representable range.

Source

pub fn checked_sub_signed(self, d: Duration) -> Option<Self>

self - d, None outside the representable range.

Source

pub fn trunc_subsecs_to_secs(self) -> Self

The instant truncated to whole seconds (towards the past).

Source

pub fn to_system_time(self) -> SystemTime

The instant as a SystemTime.

Trait Implementations§

Source§

impl Add<Duration> for UtcDateTime

Source§

type Output = UtcDateTime

The resulting type after applying the + operator.
Source§

fn add(self, d: Duration) -> Self

Performs the + operation. Read more
Source§

impl Add<Duration> for UtcDateTime

Source§

type Output = UtcDateTime

The resulting type after applying the + operator.
Source§

fn add(self, d: Duration) -> Self

Performs the + operation. Read more
Source§

impl AddAssign<Duration> for UtcDateTime

Source§

fn add_assign(&mut self, d: Duration)

Performs the += operation. Read more
Source§

impl Clone for UtcDateTime

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for UtcDateTime

Source§

impl Debug for UtcDateTime

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for UtcDateTime

Source§

fn default() -> Self

The Unix epoch.

Source§

impl<'de> Deserialize<'de> for UtcDateTime

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for UtcDateTime

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

2026-11-17 10:00:00 UTC, with 3, 6 or 9 fractional digits when the instant has them.

Source§

impl Eq for UtcDateTime

Source§

impl From<OffsetDateTime> for UtcDateTime

Source§

fn from(t: OffsetDateTime) -> Self

Converts to this type from the input type.
Source§

impl From<SystemTime> for UtcDateTime

Source§

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

Source§

fn from(ts: Timestamp) -> Self

Converts to this type from the input type.
Source§

impl From<UtcDateTime> for SystemTime

Source§

fn from(t: UtcDateTime) -> Self

Converts to this type from the input type.
Source§

impl From<UtcDateTime> for Timestamp

Source§

fn from(t: UtcDateTime) -> Self

Converts to this type from the input type.
Source§

impl FromStr for UtcDateTime

Source§

fn from_str(s: &str) -> Result<Self, ParseError>

Relaxed RFC 3339: what serde accepts.

Source§

type Err = ParseError

The associated error which can be returned from parsing.
Source§

impl Hash for UtcDateTime

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for UtcDateTime

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl PartialEq for UtcDateTime

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<OffsetDateTime> for UtcDateTime

Source§

fn eq(&self, other: &OffsetDateTime) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq<UtcDateTime> for OffsetDateTime

Source§

fn eq(&self, other: &UtcDateTime) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for UtcDateTime

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl PartialOrd<OffsetDateTime> for UtcDateTime

Source§

fn partial_cmp(&self, other: &OffsetDateTime) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl PartialOrd<UtcDateTime> for OffsetDateTime

Source§

fn partial_cmp(&self, other: &UtcDateTime) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for UtcDateTime

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for UtcDateTime

Source§

impl Sub for UtcDateTime

Source§

type Output = Duration

The resulting type after applying the - operator.
Source§

fn sub(self, other: Self) -> Duration

Performs the - operation. Read more
Source§

impl Sub<Duration> for UtcDateTime

Source§

type Output = UtcDateTime

The resulting type after applying the - operator.
Source§

fn sub(self, d: Duration) -> Self

Performs the - operation. Read more
Source§

impl Sub<Duration> for UtcDateTime

Source§

type Output = UtcDateTime

The resulting type after applying the - operator.
Source§

fn sub(self, d: Duration) -> Self

Performs the - operation. Read more
Source§

impl Sub<OffsetDateTime> for UtcDateTime

Source§

type Output = Duration

The resulting type after applying the - operator.
Source§

fn sub(self, other: OffsetDateTime) -> Duration

Performs the - operation. Read more
Source§

impl Sub<UtcDateTime> for OffsetDateTime

Source§

type Output = Duration

The resulting type after applying the - operator.
Source§

fn sub(self, other: UtcDateTime) -> Duration

Performs the - operation. Read more
Source§

impl SubAssign<Duration> for UtcDateTime

Source§

fn sub_assign(&mut self, d: Duration)

Performs the -= operation. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.