//不刷新输出日期时间
use chrono::prelude::*;
use std::thread;
use std::time::Duration;
fn main() {
loop {
let now = Local::now();
println!("{}", now.format("%Y-%m-%d %H:%M:%S"));
thread::sleep(Duration::from_secs(1)); // 暂停 1 秒钟
}
}
//输出日期时间刷新屏幕
use std::io::{self, Write};
use std::thread;
use std::time::Duration;
use chrono::prelude::*;
fn main() -> io::Result<()> {
let stdout = io::stdout();
let mut handle = stdout.lock();
loop {
let now = Local::now();
write!(handle, "{}\r", now.format("%Y-%m-%d %H:%M:%S"))?;
handle.flush()?;
thread::sleep(Duration::from_secs(1)); // 暂停 1 秒钟
}
}
如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!
txttool.com 说一段 esp56物联 查询128 IP查询