feat: add filename formatting
Diff
Cargo.toml | 1 +
src/main.rs | 8 +++++++-
2 files changed, 8 insertions(+), 1 deletion(-)
@@ -6,4 +6,5 @@ edition = "2021"
[dependencies]
chrono = "0.4.31"
screenshots = "0.8.6"
@@ -1,3 +1,4 @@
use chrono::{DateTime, Local, Utc};
use screenshots::{image::ImageBuffer, Screen};
fn main() {
@@ -39,7 +40,12 @@ fn capture_all() {
});
if !img.is_empty() {
match img.save("target/capture.png") {
let filename: DateTime<Local> = Utc::now().with_timezone(&Local);
match img.save(format!(
"target/{}.png",
filename.format("%Y-%m-%d_%H-%M-%S")
)) {
Ok(_) => println!("screenshot saved successfully!"),
Err(err) => println!("there was an error saving the image: {:?}", err),
}