erg/compiler/erg_common/datetime.rs
Shunsuke Shibayama 6921189a95 Update datetime.rs
2022-08-17 23:08:56 +09:00

20 lines
652 B
Rust

use std::process::Command;
/// returns the current datetime as String
pub fn now() -> String {
let output = if cfg!(windows) {
Command::new("cmd")
.args(&["/C", "echo %date% %time%"])
.output()
.expect("failed to execute a process to get current time")
} else {
Command::new("date")
.args(&["+%Y/%m/%d %T"])
.output()
.expect("failed to execute process to get current time")
};
String::from_utf8(output.stdout.clone())
.unwrap_or_else(|_| String::from_utf8_lossy(&output.stdout[..]).to_string())
.trim_end()
.to_string()
}