I want to display the current time in a specific format.
I am trying to avoid time crate as it is marked as deprecated on the GitHub repository .
I want to use this exact format time::now().strftime("%Y-%m-%d][%H:%M:%S").unwrap()with help std::time, but it doesn’t strftime.
time::now().strftime("%Y-%m-%d][%H:%M:%S").unwrap()
std::time
strftime
There are (currently) two methods now: Instant::nowand SystemTime::now.
now
Instant::now
SystemTime::now
Instant He speaks:
Instant
Measurement of monotonically increasing hours. Opaque and useful only with Duration.
Duration
SystemTime He speaks:
SystemTime
Measuring system clocks useful for communicating with external objects, such as a file system or other processes.
. , - . , , API, .
, chrono, time.
time
chrono :
chrono
extern crate chrono; use chrono::Local; fn main() { let date = Local::now(); println!("{}", date.format("%Y-%m-%d][%H:%M:%S")); }
Edit:
: .
, , .
Source: https://habr.com/ru/post/1651296/More articles:Enable wordwrap (multi-line) in vaadin grid - vaadinCreating hidden tabbable / 508 Compliant radio buttons - htmlHow to create a permanent list of changes from the command line - windowsWhere is the error in my algorithm to determine if there is a permutation of two arrays A, B such that they have (A [i] + B [i])> = k - arraysHow can I make my modified tabbable switches? - htmlHow do pipes work in Rust By Example? - multithreadingRun the void installation method in Spring Context @ Configuration - javaHow to count 5 minutes? - rustError data resolutionLayer undefined - google-tag-managerFailed to load download file to store files running python-eve - storageAll Articles