pub struct Datetime { /* private fields */ }
Expand description
Datetime
§Example
let mut dt = Datetime::default();
dt.add_years(1970).add_months(1).add_days(1);
dt.add_seconds(Datetime::timestamp().as_secs() as i64);
let now = Datetime::now();
assert!(dt == now);
Implementations§
Source§impl Datetime
impl Datetime
Sourcepub fn add_months(&mut self, months: i64) -> &mut Self
pub fn add_months(&mut self, months: i64) -> &mut Self
plus months
Sourcepub fn add_hours(&mut self, hours: i64) -> &mut Self
pub fn add_hours(&mut self, hours: i64) -> &mut Self
plus hours
let mut dt = Datetime::now();
dt.add_hours(8);
println!("{}", dt);
Sourcepub fn add_minutes(&mut self, minutes: i64) -> &mut Self
pub fn add_minutes(&mut self, minutes: i64) -> &mut Self
plus minutes
Sourcepub fn add_seconds(&mut self, seconds: i64) -> &mut Self
pub fn add_seconds(&mut self, seconds: i64) -> &mut Self
plus seconds
pub fn year(&self) -> i64
pub fn month(&self) -> i64
pub fn day(&self) -> i64
pub fn hour(&self) -> i64
pub fn minute(&self) -> i64
pub fn second(&self) -> i64
Sourcepub fn day_of_week(&self) -> &'static str
pub fn day_of_week(&self) -> &'static str
may be used to obtain the day of the week for dates on or after 0000-03-01
assert_eq!(
Datetime::from_rfc3339("1970-01-01").unwrap().day_of_week(),
"Thursday"
);
Sourcepub fn seconds_since(&self, earlier: Datetime) -> i64
pub fn seconds_since(&self, earlier: Datetime) -> i64
the number of seconds between two Datetime
assert_eq!(
Datetime::now().seconds_since(Datetime::from_rfc3339("1970-01-01").unwrap()),
Datetime::timestamp().as_secs() as i64
);
Sourcepub fn from_rfc3339(rfc: &str) -> Option<Self>
pub fn from_rfc3339(rfc: &str) -> Option<Self>
create from rfc3339 string
assert_eq!(
Datetime::from_rfc3339("2020-01-01 08:00:00+08:00")
.unwrap()
.to_string(),
"2020-01-01 00:00:00"
);
Trait Implementations§
Source§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>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialOrd for Datetime
impl PartialOrd for Datetime
impl Copy 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
Mutably borrows from an owned value. Read more