pub struct DateTime(/* private fields */);Expand description
A wrapper type for chrono::DateTime<Local>.
Implementations§
Source§impl DateTime
impl DateTime
Sourcepub fn current_timestamp() -> i64
pub fn current_timestamp() -> i64
Returns the number of non-leap seconds since the midnight UTC on January 1, 1970.
Sourcepub fn current_timestamp_millis() -> i64
pub fn current_timestamp_millis() -> i64
Returns the number of non-leap milliseconds since the midnight UTC on January 1, 1970.
Sourcepub fn current_timestamp_micros() -> i64
pub fn current_timestamp_micros() -> i64
Returns the number of non-leap microseconds since the midnight UTC on January 1, 1970.
Sourcepub fn current_timestamp_nanos() -> i64
pub fn current_timestamp_nanos() -> i64
Returns the number of non-leap nanoseconds since the midnight UTC on January 1, 1970.
Sourcepub fn from_timestamp(secs: i64) -> Self
pub fn from_timestamp(secs: i64) -> Self
Returns a new instance corresponding to a UTC date and time, from the number of non-leap seconds since the midnight UTC on January 1, 1970.
Sourcepub fn from_timestamp_millis(millis: i64) -> Self
pub fn from_timestamp_millis(millis: i64) -> Self
Returns a new instance corresponding to a UTC date and time, from the number of non-leap milliseconds since the midnight UTC on January 1, 1970.
Sourcepub fn from_timestamp_micros(micros: i64) -> Self
pub fn from_timestamp_micros(micros: i64) -> Self
Returns a new instance corresponding to a UTC date and time, from the number of non-leap microseconds since the midnight UTC on January 1, 1970.
Sourcepub fn from_timestamp_nanos(nanos: i64) -> Self
pub fn from_timestamp_nanos(nanos: i64) -> Self
Returns a new instance corresponding to a UTC date and time, from the number of non-leap nanoseconds since the midnight UTC on January 1, 1970.
Sourcepub fn from_uuid_timestamp(ts: Timestamp) -> Self
pub fn from_uuid_timestamp(ts: Timestamp) -> Self
Returns a new instance corresponding to a UTC date and time from a UUID timestamp.
Sourcepub fn timestamp(&self) -> i64
pub fn timestamp(&self) -> i64
Returns the number of non-leap seconds since the midnight UTC on January 1, 1970.
Sourcepub fn timestamp_millis(&self) -> i64
pub fn timestamp_millis(&self) -> i64
Returns the number of non-leap milliseconds since the midnight UTC on January 1, 1970.
Sourcepub fn timestamp_micros(&self) -> i64
pub fn timestamp_micros(&self) -> i64
Returns the number of non-leap microseconds since the midnight UTC on January 1, 1970.
Sourcepub fn timestamp_nanos(&self) -> i64
pub fn timestamp_nanos(&self) -> i64
Returns the number of non-leap nanoseconds since the midnight UTC on January 1, 1970.
Sourcepub fn uuid_timestamp(&self) -> Timestamp
pub fn uuid_timestamp(&self) -> Timestamp
Returns a timestamp that can be encoded into a UUID.
Sourcepub fn timezone_offset(&self) -> i32
pub fn timezone_offset(&self) -> i32
Returns the difference in seconds between self and
the same date-time as evaluated in the UTC time zone.
Sourcepub fn parse_utc_str(s: &str) -> Result<Self, ParseError>
pub fn parse_utc_str(s: &str) -> Result<Self, ParseError>
Parses an RFC 2822 date and time.
Sourcepub fn parse_iso_str(s: &str) -> Result<Self, ParseError>
pub fn parse_iso_str(s: &str) -> Result<Self, ParseError>
Parses an RFC 3339 and ISO 8601 date and time.
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 a string with the specified format string.
See format::strftime for the supported escape sequences.
Sourcepub fn to_utc_timestamp(&self) -> String
pub fn to_utc_timestamp(&self) -> String
Returns a UTC timestamp string.
Sourcepub fn to_utc_string(&self) -> String
pub fn to_utc_string(&self) -> String
Returns an RFC 2822 date and time string.
Sourcepub fn to_iso_string(&self) -> String
pub fn to_iso_string(&self) -> String
Return an RFC 3339 and ISO 8601 date and time string with subseconds
formatted as SecondsFormat::Millis.
Sourcepub fn to_local_string(&self) -> String
pub fn to_local_string(&self) -> String
Returns a date-time string with the Local time zone.
Sourcepub fn format(&self, fmt: &str) -> String
pub fn format(&self, fmt: &str) -> String
Formats the combined date and time with the specified format string.
See format::strftime for the supported escape sequences.
Sourcepub fn format_date(&self) -> String
pub fn format_date(&self) -> String
Returns a date-only string in the format %Y-%m-%d.
Sourcepub fn format_time(&self) -> String
pub fn format_time(&self) -> String
Returns a time-only string in the format %H:%M:%S.
Sourcepub fn format_local(&self) -> String
pub fn format_local(&self) -> String
Returns a date-time string in the format %Y-%m-%d %H:%M:%S with the Local time zone.
Sourcepub fn format_utc(&self) -> String
pub fn format_utc(&self) -> String
Returns a date-time string in the format %Y-%m-%d %H:%M:%S with the Utc time zone.
Sourcepub fn duration_since(&self, earlier: DateTime) -> Duration
pub fn duration_since(&self, earlier: DateTime) -> Duration
Returns the amount of time elapsed from another datetime to this one, or zero duration if that datetime is later than this one.
Sourcepub fn span_between(&self, other: DateTime) -> Duration
pub fn span_between(&self, other: DateTime) -> Duration
Returns the duration of time between self and other.
Sourcepub fn span_between_now(&self) -> Duration
pub fn span_between_now(&self) -> Duration
Returns the duration of time between self and DateTime::now().
Sourcepub fn span_before_now(&self) -> Option<Duration>
pub fn span_before_now(&self) -> Option<Duration>
Returns the duration of time from self to DateTime::now().
Sourcepub fn span_after_now(&self) -> Option<Duration>
pub fn span_after_now(&self) -> Option<Duration>
Returns the duration of time from DateTime::now() to self.
Sourcepub fn quarter(&self) -> u32
pub fn quarter(&self) -> u32
Returns the quarter number starting from 1.
The return value ranges from 1 to 4.
Sourcepub fn month(&self) -> u32
pub fn month(&self) -> u32
Returns the month number starting from 1.
The return value ranges from 1 to 12.
Sourcepub fn day(&self) -> u32
pub fn day(&self) -> u32
Returns the day of month starting from 1.
The return value ranges from 1 to 31. (The last day of month differs by months.)
Sourcepub fn millisecond(&self) -> u32
pub fn millisecond(&self) -> u32
Returns the millisecond number from 0 to 999.
Sourcepub fn microsecond(&self) -> u32
pub fn microsecond(&self) -> u32
Returns the microsecond number from 0 to 999.
Sourcepub fn nanosecond(&self) -> u32
pub fn nanosecond(&self) -> u32
Returns the nanosecond number from 0 to 999.
Sourcepub fn week(&self) -> u32
pub fn week(&self) -> u32
Returns the ISO week number starting from 1.
The return value ranges from 1 to 53. (The last week of year differs by years.)
Sourcepub fn day_of_year(&self) -> u32
pub fn day_of_year(&self) -> u32
Returns the day of year starting from 1.
The return value ranges from 1 to 366. (The last day of year differs by years.)
Sourcepub fn day_of_week(&self) -> u8
pub fn day_of_week(&self) -> u8
Returns the day of week starting from 0 (Sunday) to 6 (Saturday).
Sourcepub fn iso_day_of_week(&self) -> u8
pub fn iso_day_of_week(&self) -> u8
Returns the ISO day of week starting from 1 (Monday) to 7 (Sunday).
Sourcepub fn is_leap_year(&self) -> bool
pub fn is_leap_year(&self) -> bool
Returns true if the current year is a leap year.
Sourcepub fn is_weekend(&self) -> bool
pub fn is_weekend(&self) -> bool
Returns true if the current day is weekend.
Sourcepub fn days_in_current_year(&self) -> u32
pub fn days_in_current_year(&self) -> u32
Returns the number of days in the current year.
Sourcepub fn days_in_current_month(&self) -> u32
pub fn days_in_current_month(&self) -> u32
Returns the number of days in the current month.
Sourcepub fn start_of_current_year(&self) -> Self
pub fn start_of_current_year(&self) -> Self
Returns the start of the current year.
Sourcepub fn end_of_current_year(&self) -> Self
pub fn end_of_current_year(&self) -> Self
Returns the end of the current year.
Sourcepub fn start_of_current_quarter(&self) -> Self
pub fn start_of_current_quarter(&self) -> Self
Returns the start of the current quarter.
Sourcepub fn end_of_current_quarter(&self) -> Self
pub fn end_of_current_quarter(&self) -> Self
Returns the end of the current quarter.
Sourcepub fn start_of_current_month(&self) -> Self
pub fn start_of_current_month(&self) -> Self
Returns the start of the current month.
Sourcepub fn end_of_current_month(&self) -> Self
pub fn end_of_current_month(&self) -> Self
Returns the end of the current month.
Sourcepub fn start_of_current_day(&self) -> Self
pub fn start_of_current_day(&self) -> Self
Returns the start of the current day.
Sourcepub fn end_of_current_day(&self) -> Self
pub fn end_of_current_day(&self) -> Self
Returns the end of the current day.
Sourcepub fn start_of_year(year: i32) -> Self
pub fn start_of_year(year: i32) -> Self
Returns the start of the year.
Sourcepub fn end_of_year(year: i32) -> Self
pub fn end_of_year(year: i32) -> Self
Returns the end of the year.
Sourcepub fn start_of_month(year: i32, month: u32) -> Self
pub fn start_of_month(year: i32, month: u32) -> Self
Returns the start of the month.
Sourcepub fn end_of_month(year: i32, month: u32) -> Self
pub fn end_of_month(year: i32, month: u32) -> Self
Returns the end of the month.
Sourcepub fn start_of_day(year: i32, month: u32, day: u32) -> Self
pub fn start_of_day(year: i32, month: u32, day: u32) -> Self
Returns the start of the day.
Sourcepub fn end_of_day(year: i32, month: u32, day: u32) -> Self
pub fn end_of_day(year: i32, month: u32, day: u32) -> Self
Returns the end of the month.
Sourcepub fn checked_add_months(self, months: u32) -> Option<Self>
pub fn checked_add_months(self, months: u32) -> Option<Self>
Adds a duration in months to the date part of the DateTime.
Returns None if the resulting date would be out of range.
Sourcepub fn checked_sub_months(self, months: u32) -> Option<Self>
pub fn checked_sub_months(self, months: u32) -> Option<Self>
Subtracts a duration in months from the date part of the DateTime.
Returns None if the resulting date would be out of range.
Sourcepub fn checked_add_days(self, days: u32) -> Option<Self>
pub fn checked_add_days(self, days: u32) -> Option<Self>
Adds a duration in days to the date part of the DateTime.
Returns None if the resulting date would be out of range.
Sourcepub fn checked_sub_days(self, days: u32) -> Option<Self>
pub fn checked_sub_days(self, days: u32) -> Option<Self>
Subtracts a duration in days from the date part of the DateTime.
Returns None if the resulting date would be out of range.
Trait Implementations§
Source§impl AddAssign<Duration> for DateTime
impl AddAssign<Duration> for DateTime
Source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
+= operation. Read moreSource§impl<'de> Deserialize<'de> for DateTime
impl<'de> Deserialize<'de> for DateTime
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl<'a> From<DateTime> for FluentValue<'a>
Available on crate feature i18n only.
impl<'a> From<DateTime> for FluentValue<'a>
i18n only.Source§impl Ord for DateTime
impl Ord for DateTime
Source§impl PartialOrd for DateTime
impl PartialOrd for DateTime
Source§impl SubAssign<Duration> for DateTime
impl SubAssign<Duration> for DateTime
Source§fn sub_assign(&mut self, rhs: Duration)
fn sub_assign(&mut self, rhs: Duration)
-= operation. Read moreimpl Copy for DateTime
impl Eq for DateTime
impl StructuralPartialEq for DateTime
Auto Trait Implementations§
impl Freeze for DateTime
impl RefUnwindSafe for DateTime
impl Send for DateTime
impl Sync for DateTime
impl Unpin for DateTime
impl UnwindSafe for DateTime
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.