erg_common/
datetime.rs

1use std::process::Command;
2
3/// returns the current datetime as String
4pub fn now() -> String {
5    let output = if cfg!(windows) {
6        Command::new("cmd")
7            .args(["/C", "echo %date:~0,10% %time%"])
8            .output()
9            .expect("failed to execute a process to get current time")
10    } else {
11        Command::new("date")
12            .args(["+%Y/%m/%d %T"])
13            .output()
14            .expect("failed to execute process to get current time")
15    };
16    String::from_utf8_lossy(&output.stdout[..])
17        .trim_end()
18        .to_string()
19}