pub struct UtcDatetime { /* private fields */ }
Implementations§
Source§impl UtcDatetime
impl UtcDatetime
Sourcepub fn new(
year: u16,
month: u8,
day: u8,
hour: u8,
minute: u8,
second: u8,
) -> Result<UtcDatetime, IllegalTimeError>
pub fn new( year: u16, month: u8, day: u8, hour: u8, minute: u8, second: u8, ) -> Result<UtcDatetime, IllegalTimeError>
Create a new UtcDateTime structure
Sourcepub fn timestamp(&self) -> Result<u32, IllegalTimeError>
pub fn timestamp(&self) -> Result<u32, IllegalTimeError>
Returns the number of seconds since January 1, 1970
§Example
use utc_datetime::UtcDatetime;
let anew_date=UtcDatetime::new(2020,2,2,2,2,2).unwrap();
assert_eq!(anew_date.timestamp().unwrap(),1580608922)
Sourcepub fn weekday(&self) -> u8
pub fn weekday(&self) -> u8
Return today is the day of the week,Monday to Saturday Return 1 to 6,Sunday return 0
§Example
use utc_datetime::UtcDatetime;
let a_date=UtcDatetime::new(2021,11,15,0,0,0).unwrap();
assert_eq!(a_date.weekday(),1);
Sourcepub fn from_string(time_str: &str) -> Result<UtcDatetime, IllegalTimeError>
pub fn from_string(time_str: &str) -> Result<UtcDatetime, IllegalTimeError>
Convert a string containing time to UtcDatetime.
Time strings must be sorted by year, month, day, hour, minute, and second, and Non-arabic numbers can be used as separators.
Parsable string example:“2020-12-31 23:59:59”,“2020z12z31z23z59z59”.
§Example
use utc_datetime::UtcDatetime;
let datetime=UtcDatetime::from_string("时间:2020年12月31日23点59分59秒").unwrap();
assert_eq!(datetime,UtcDatetime::new(2020,12,31,23,59,59).unwrap());
Trait Implementations§
Source§impl Debug for UtcDatetime
impl Debug for UtcDatetime
Source§impl Display for UtcDatetime
impl Display for UtcDatetime
Source§impl PartialEq for UtcDatetime
impl PartialEq for UtcDatetime
Source§impl PartialOrd for UtcDatetime
impl PartialOrd for UtcDatetime
impl StructuralPartialEq for UtcDatetime
Auto Trait Implementations§
impl Freeze for UtcDatetime
impl RefUnwindSafe for UtcDatetime
impl Send for UtcDatetime
impl Sync for UtcDatetime
impl Unpin for UtcDatetime
impl UnwindSafe for UtcDatetime
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