pub struct ScriptTime<T = ()> { /* private fields */ }
Expand description
可能帶著資料的時間。 如果有資料,代表「這些資料是新的產生,應儲存起來但還未存」 如果沒資料,就視為上次儲存的一個快照,只記得時間就好,因為我們通常不會需要上一次存下的資料
Implementations§
Source§impl<T> ScriptTime<T>
impl<T> ScriptTime<T>
Methods from Deref<Target = NaiveDateTime>§
pub const MIN: NaiveDateTime
pub const MAX: NaiveDateTime
pub const UNIX_EPOCH: NaiveDateTime
Sourcepub fn date(&self) -> NaiveDate
pub fn date(&self) -> NaiveDate
Retrieves a date component.
§Example
use chrono::NaiveDate;
let dt = NaiveDate::from_ymd_opt(2016, 7, 8).unwrap().and_hms_opt(9, 10, 11).unwrap();
assert_eq!(dt.date(), NaiveDate::from_ymd_opt(2016, 7, 8).unwrap());
Sourcepub fn time(&self) -> NaiveTime
pub fn time(&self) -> NaiveTime
Retrieves a time component.
§Example
use chrono::{NaiveDate, NaiveTime};
let dt = NaiveDate::from_ymd_opt(2016, 7, 8).unwrap().and_hms_opt(9, 10, 11).unwrap();
assert_eq!(dt.time(), NaiveTime::from_hms_opt(9, 10, 11).unwrap());
Sourcepub fn timestamp(&self) -> i64
👎Deprecated since 0.4.35: use .and_utc().timestamp()
instead
pub fn timestamp(&self) -> i64
.and_utc().timestamp()
insteadReturns the number of non-leap seconds since the midnight on January 1, 1970.
Note that this does not account for the timezone! The true “UNIX timestamp” would count seconds since the midnight UTC on the epoch.
Sourcepub fn timestamp_millis(&self) -> i64
👎Deprecated since 0.4.35: use .and_utc().timestamp_millis()
instead
pub fn timestamp_millis(&self) -> i64
.and_utc().timestamp_millis()
insteadReturns the number of non-leap milliseconds since midnight on January 1, 1970.
Note that this does not account for the timezone! The true “UNIX timestamp” would count seconds since the midnight UTC on the epoch.
Sourcepub fn timestamp_micros(&self) -> i64
👎Deprecated since 0.4.35: use .and_utc().timestamp_micros()
instead
pub fn timestamp_micros(&self) -> i64
.and_utc().timestamp_micros()
insteadReturns the number of non-leap microseconds since midnight on January 1, 1970.
Note that this does not account for the timezone! The true “UNIX timestamp” would count seconds since the midnight UTC on the epoch.
Sourcepub fn timestamp_nanos(&self) -> i64
👎Deprecated since 0.4.31: use .and_utc().timestamp_nanos_opt()
instead
pub fn timestamp_nanos(&self) -> i64
.and_utc().timestamp_nanos_opt()
insteadReturns the number of non-leap nanoseconds since midnight on January 1, 1970.
Note that this does not account for the timezone! The true “UNIX timestamp” would count seconds since the midnight UTC on the epoch.
§Panics
An i64
with nanosecond precision can span a range of ~584 years. This function panics on
an out of range NaiveDateTime
.
The dates that can be represented as nanoseconds are between 1677-09-21T00:12:43.145224192 and 2262-04-11T23:47:16.854775807.
Sourcepub fn timestamp_nanos_opt(&self) -> Option<i64>
👎Deprecated since 0.4.35: use .and_utc().timestamp_nanos_opt()
instead
pub fn timestamp_nanos_opt(&self) -> Option<i64>
.and_utc().timestamp_nanos_opt()
insteadReturns the number of non-leap nanoseconds since midnight on January 1, 1970.
Note that this does not account for the timezone! The true “UNIX timestamp” would count seconds since the midnight UTC on the epoch.
§Errors
An i64
with nanosecond precision can span a range of ~584 years. This function returns
None
on an out of range NaiveDateTime
.
The dates that can be represented as nanoseconds are between 1677-09-21T00:12:43.145224192 and 2262-04-11T23:47:16.854775807.
Sourcepub fn timestamp_subsec_millis(&self) -> u32
👎Deprecated since 0.4.35: use .and_utc().timestamp_subsec_millis()
instead
pub fn timestamp_subsec_millis(&self) -> u32
.and_utc().timestamp_subsec_millis()
insteadReturns the number of milliseconds since the last whole non-leap second.
The return value ranges from 0 to 999, or for leap seconds, to 1,999.
Sourcepub fn timestamp_subsec_micros(&self) -> u32
👎Deprecated since 0.4.35: use .and_utc().timestamp_subsec_micros()
instead
pub fn timestamp_subsec_micros(&self) -> u32
.and_utc().timestamp_subsec_micros()
insteadReturns the number of microseconds since the last whole non-leap second.
The return value ranges from 0 to 999,999, or for leap seconds, to 1,999,999.
Sourcepub fn timestamp_subsec_nanos(&self) -> u32
👎Deprecated since 0.4.36: use .and_utc().timestamp_subsec_nanos()
instead
pub fn timestamp_subsec_nanos(&self) -> u32
.and_utc().timestamp_subsec_nanos()
insteadReturns the number of nanoseconds since the last whole non-leap second.
The return value ranges from 0 to 999,999,999, or for leap seconds, to 1,999,999,999.
Sourcepub fn format_with_items<'a, I, B>(&self, items: I) -> DelayedFormat<I>
pub fn format_with_items<'a, I, B>(&self, items: I) -> DelayedFormat<I>
Formats the combined date and time with the specified formatting items.
Otherwise it is the same as the ordinary format
method.
The Iterator
of items should be Clone
able,
since the resulting DelayedFormat
value may be formatted multiple times.
§Example
use chrono::format::strftime::StrftimeItems;
use chrono::NaiveDate;
let fmt = StrftimeItems::new("%Y-%m-%d %H:%M:%S");
let dt = NaiveDate::from_ymd_opt(2015, 9, 5).unwrap().and_hms_opt(23, 56, 4).unwrap();
assert_eq!(dt.format_with_items(fmt.clone()).to_string(), "2015-09-05 23:56:04");
assert_eq!(dt.format("%Y-%m-%d %H:%M:%S").to_string(), "2015-09-05 23:56:04");
The resulting DelayedFormat
can be formatted directly via the Display
trait.
assert_eq!(format!("{}", dt.format_with_items(fmt)), "2015-09-05 23:56:04");
Sourcepub fn format<'a>(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>>
pub fn format<'a>(&self, fmt: &'a str) -> DelayedFormat<StrftimeItems<'a>>
Formats the combined date and time with the specified format string.
See the format::strftime
module
on the supported escape sequences.
This returns a DelayedFormat
,
which gets converted to a string only when actual formatting happens.
You may use the to_string
method to get a String
,
or just feed it into print!
and other formatting macros.
(In this way it avoids the redundant memory allocation.)
A wrong format string does not issue an error immediately.
Rather, converting or formatting the DelayedFormat
fails.
You are recommended to immediately use DelayedFormat
for this reason.
§Example
use chrono::NaiveDate;
let dt = NaiveDate::from_ymd_opt(2015, 9, 5).unwrap().and_hms_opt(23, 56, 4).unwrap();
assert_eq!(dt.format("%Y-%m-%d %H:%M:%S").to_string(), "2015-09-05 23:56:04");
assert_eq!(dt.format("around %l %p on %b %-d").to_string(), "around 11 PM on Sep 5");
The resulting DelayedFormat
can be formatted directly via the Display
trait.
assert_eq!(format!("{}", dt.format("%Y-%m-%d %H:%M:%S")), "2015-09-05 23:56:04");
assert_eq!(format!("{}", dt.format("around %l %p on %b %-d")), "around 11 PM on Sep 5");
Sourcepub fn and_local_timezone<Tz>(&self, tz: Tz) -> LocalResult<DateTime<Tz>>where
Tz: TimeZone,
pub fn and_local_timezone<Tz>(&self, tz: Tz) -> LocalResult<DateTime<Tz>>where
Tz: TimeZone,
Converts the NaiveDateTime
into a timezone-aware DateTime<Tz>
with the provided
time zone.
§Example
use chrono::{FixedOffset, NaiveDate};
let hour = 3600;
let tz = FixedOffset::east_opt(5 * hour).unwrap();
let dt = NaiveDate::from_ymd_opt(2015, 9, 5)
.unwrap()
.and_hms_opt(23, 56, 4)
.unwrap()
.and_local_timezone(tz)
.unwrap();
assert_eq!(dt.timezone(), tz);
Trait Implementations§
Source§impl<T: Clone> Clone for ScriptTime<T>
impl<T: Clone> Clone for ScriptTime<T>
Source§fn clone(&self) -> ScriptTime<T>
fn clone(&self) -> ScriptTime<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<T: Debug> Debug for ScriptTime<T>
impl<T: Debug> Debug for ScriptTime<T>
Source§impl<T> Deref for ScriptTime<T>
impl<T> Deref for ScriptTime<T>
Source§impl<T> Ord for ScriptTime<T>
impl<T> Ord for ScriptTime<T>
Source§impl<T> PartialEq for ScriptTime<T>
impl<T> PartialEq for ScriptTime<T>
Source§impl<T> PartialOrd for ScriptTime<T>
impl<T> PartialOrd for ScriptTime<T>
impl<T: Copy> Copy for ScriptTime<T>
impl<T> Eq for ScriptTime<T>
Auto Trait Implementations§
impl<T> Freeze for ScriptTime<T>where
T: Freeze,
impl<T> RefUnwindSafe for ScriptTime<T>where
T: RefUnwindSafe,
impl<T> Send for ScriptTime<T>where
T: Send,
impl<T> Sync for ScriptTime<T>where
T: Sync,
impl<T> Unpin for ScriptTime<T>where
T: Unpin,
impl<T> UnwindSafe for ScriptTime<T>where
T: UnwindSafe,
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<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<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 more