Skip to main content

DateTime

Struct DateTime 

Source
#[repr(C)]
pub struct DateTime { pub universal_time: i64, }

Fields§

§universal_time: i64

Implementations§

Source§

impl DateTime

Source

pub const UNIX_EPOCH: DateTime

The DateTime value corresponding to 1970-01-01 00:00:00 UTC.

Source

pub const MIN: DateTime

The minimum representable DateTime (i64::MIN ticks).

Source

pub const MAX: DateTime

The maximum representable DateTime (i64::MAX ticks).

Source

pub const TICKS_PER_SECOND: i64 = TICKS_PER_SECOND

The number of 100-nanosecond ticks per second (matches TimeSpan::TICKS_PER_SECOND).

Source

pub const fn from_ticks(ticks: i64) -> DateTime

Constructs a DateTime from a raw count of 100-nanosecond ticks since 1601-01-01 00:00:00 UTC.

Source

pub const fn from_unix_secs(secs: i64) -> DateTime

Constructs a DateTime from a number of whole seconds since the Unix epoch, saturating on overflow.

Source

pub const fn from_unix_millis(millis: i64) -> DateTime

Constructs a DateTime from a number of whole milliseconds since the Unix epoch, saturating on overflow.

Source

pub const fn ticks(self) -> i64

Returns the raw count of 100-nanosecond ticks since 1601-01-01 UTC.

Source

pub const fn unix_secs(self) -> i64

Returns the number of whole seconds between this DateTime and the Unix epoch. Negative for pre-1970 values.

Source

pub const fn unix_millis(self) -> i64

Returns the number of whole milliseconds between this DateTime and the Unix epoch. Negative for pre-1970 values.

Source

pub const fn unix_nanos(self) -> i128

Returns the number of nanoseconds between this DateTime and the Unix epoch, as an i128 to avoid overflow.

Source

pub const fn checked_add(self, rhs: TimeSpan) -> Option<DateTime>

Checked addition of a TimeSpan. Returns None on overflow.

Source

pub const fn checked_sub(self, rhs: TimeSpan) -> Option<DateTime>

Checked subtraction of a TimeSpan. Returns None on overflow.

Source

pub const fn checked_duration_since(self, earlier: DateTime) -> Option<TimeSpan>

Returns the signed duration from earlier to self. Returns None on overflow.

Source

pub const fn saturating_add(self, rhs: TimeSpan) -> DateTime

Saturating addition of a TimeSpan.

Source

pub const fn saturating_sub(self, rhs: TimeSpan) -> DateTime

Saturating subtraction of a TimeSpan.

Source

pub fn now() -> DateTime

Returns the current DateTime from the system clock.

Source

pub fn to_local(self) -> DateTime

Converts this DateTime from UTC to local time by applying the system’s current timezone offset (including DST adjustments).

The returned DateTime has its ticks shifted so that the decomposition methods (year, month, day, etc.) return local calendar values.

§Example
use windows_time::DateTime;

let local = DateTime::now().to_local();
println!("{:02}:{:02}:{:02}", local.hour(), local.minute(), local.second());
Source

pub const fn year(self) -> i64

The year component of this DateTime.

Source

pub const fn month(self) -> u32

The month component (1 = January, 12 = December).

Source

pub const fn day(self) -> u32

The day of the month (1-31).

Source

pub const fn hour(self) -> u32

The hour (0-23).

Source

pub const fn minute(self) -> u32

The minute (0-59).

Source

pub const fn second(self) -> u32

The second (0-59).

Source

pub const fn milliseconds(self) -> u32

The milliseconds (0-999).

Source

pub const fn day_of_week(self) -> u32

The day of the week (0 = Sunday, 6 = Saturday).

Trait Implementations§

Source§

impl Add<TimeSpan> for DateTime

Source§

type Output = DateTime

The resulting type after applying the + operator.
Source§

fn add(self, rhs: TimeSpan) -> DateTime

Performs the + operation. Read more
Source§

impl AddAssign<TimeSpan> for DateTime

Source§

fn add_assign(&mut self, rhs: TimeSpan)

Performs the += operation. Read more
Source§

impl Clone for DateTime

Source§

fn clone(&self) -> DateTime

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 DateTime

Source§

impl Debug for DateTime

Source§

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

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

impl Default for DateTime

Source§

fn default() -> DateTime

Returns the “default value” for a type. Read more
Source§

impl Display for DateTime

ISO-8601 UTC formatting: YYYY-MM-DDTHH:MM:SS.fffffffZ. The fractional part is omitted when zero. Year is at least 4 digits, padded with a leading - for negative years.

Source§

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

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

impl Eq for DateTime

Source§

impl Hash for DateTime

Source§

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

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 DateTime

Source§

fn cmp(&self, other: &DateTime) -> 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 DateTime

Source§

fn eq(&self, other: &DateTime) -> 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 DateTime

Source§

fn partial_cmp(&self, other: &DateTime) -> 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 StructuralPartialEq for DateTime

Source§

impl Sub for DateTime

Source§

type Output = TimeSpan

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: DateTime) -> TimeSpan

Performs the - operation. Read more
Source§

impl Sub<TimeSpan> for DateTime

Source§

type Output = DateTime

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: TimeSpan) -> DateTime

Performs the - operation. Read more
Source§

impl SubAssign<TimeSpan> for DateTime

Source§

fn sub_assign(&mut self, rhs: TimeSpan)

Performs the -= operation. Read more
Source§

impl TryFrom<SystemTime> for DateTime

Available on crate feature std only.
Source§

type Error = TimeRangeError

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

fn try_from( value: SystemTime, ) -> Result<DateTime, <DateTime as TryFrom<SystemTime>>::Error>

Performs the conversion.

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