pub struct Instant { /* private fields */ }Expand description
represents times after 1970
Implementations§
Source§impl Instant
impl Instant
Sourcepub fn now() -> Self
pub fn now() -> Self
Examples found in repository?
examples/now.rs (line 18)
3fn main() {
4 let arg = std::env::args().nth(1);
5 let format = arg.as_deref().unwrap_or_default();
6
7 let format = match format {
8 "FULL_MINIMAL" | "" => FORMATS::FULL_MINIMAL,
9 "DATE_MONTH_YEAR" => FORMATS::DATE_MONTH_YEAR,
10 "MONTH_DATE_YEAR" => FORMATS::MONTH_DATE_YEAR,
11 "DATE_NAME_MONTH_YEAR" => FORMATS::DATE_NAME_MONTH_YEAR,
12 "TIME_DATE_NAME_MONTH_YEAR" => FORMATS::TIME_DATE_NAME_MONTH_YEAR,
13 "TIME" => FORMATS::TIME,
14 "TIME_WITH_SECONDS" => FORMATS::TIME_WITH_SECONDS,
15 format => format,
16 };
17
18 let now = Instant::now();
19 let formatted = now.format(format);
20 println!("{formatted}");
21}pub fn from_secs(secs: u64) -> Self
Sourcepub fn format(&self, template: &str) -> String
pub fn format(&self, template: &str) -> String
Examples found in repository?
examples/now.rs (line 19)
3fn main() {
4 let arg = std::env::args().nth(1);
5 let format = arg.as_deref().unwrap_or_default();
6
7 let format = match format {
8 "FULL_MINIMAL" | "" => FORMATS::FULL_MINIMAL,
9 "DATE_MONTH_YEAR" => FORMATS::DATE_MONTH_YEAR,
10 "MONTH_DATE_YEAR" => FORMATS::MONTH_DATE_YEAR,
11 "DATE_NAME_MONTH_YEAR" => FORMATS::DATE_NAME_MONTH_YEAR,
12 "TIME_DATE_NAME_MONTH_YEAR" => FORMATS::TIME_DATE_NAME_MONTH_YEAR,
13 "TIME" => FORMATS::TIME,
14 "TIME_WITH_SECONDS" => FORMATS::TIME_WITH_SECONDS,
15 format => format,
16 };
17
18 let now = Instant::now();
19 let formatted = now.format(format);
20 println!("{formatted}");
21}pub fn seconds(&self) -> u64
Sourcepub fn new(
year: u64,
month: u64,
day: u64,
hour: u64,
minute: u64,
second: u64,
) -> Self
pub fn new( year: u64, month: u64, day: u64, hour: u64, minute: u64, second: u64, ) -> Self
month and day are one indexed
pub fn parse_english(on: &str) -> Result<Self, &str>
Auto Trait Implementations§
impl Freeze for Instant
impl RefUnwindSafe for Instant
impl Send for Instant
impl Sync for Instant
impl Unpin for Instant
impl UnwindSafe for Instant
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