The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Rust DateTime Formatting Examples With chrono

TODO: Pull subtitle into page object
Code
//! ```cargo
//! [dependencies]
//! chrono = "0.4.31"
//! ```

use chrono::prelude::*;

fn main() {
  let date_string = "2003-01-08 04:05:06";
  let dt = NaiveDateTime::parse_from_str(date_string, "%Y-%m-%d %H:%M:%S").unwrap();
  let formats: Vec<(&str, &str)> = vec![
    ("", "%Y-%m-%d %H:%M:%S"),
    ("", "%Y-%m-%dT%H:%M:%S"),
    ("", "%B %Y"),
    ("", "%b %Y"),
  ];
  formats.iter().for_each(|format| 
    {
      println!("{}", format!("{:^24} | {:^25}", format.1, dt.format(format.1)));
    }
  );
}
Results
%Y-%m-%d %H:%M:%S     |    2003-01-08 04:05:06   
   %Y-%m-%dT%H:%M:%S     |    2003-01-08T04:05:06   
         %B %Y           |       January 2003       
         %b %Y           |         Jan 2003         

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Rust DateTime Formatting Examples With chrono

Just a few date formats I like to use

-- code
-- rust

//! ```cargo
//! [dependencies]
//! chrono = "0.4.31"
//! ```

use chrono::prelude::*;

fn main() {
  let date_string = "2003-01-08 04:05:06";
  let dt = NaiveDateTime::parse_from_str(date_string, "%Y-%m-%d %H:%M:%S").unwrap();
  let formats: Vec<(&str, &str)> = vec![
    ("", "%Y-%m-%d %H:%M:%S"),
    ("", "%Y-%m-%dT%H:%M:%S"),
    ("", "%B %Y"),
    ("", "%b %Y"),
  ];
  formats.iter().for_each(|format| 
    {
      println!("{}", format!("{:^24} | {:^25}", format.1, dt.format(format.1)));
    }
  );
}

-- results/

   %Y-%m-%d %H:%M:%S     |    2003-01-08 04:05:06   
   %Y-%m-%dT%H:%M:%S     |    2003-01-08T04:05:06   
         %B %Y           |       January 2003       
         %b %Y           |         Jan 2003         

-- /results


-- categories
-- Rust 

-- metadata
-- date: 2023-12-21 17:42:34
-- id: 2zs6gw1o
-- site: aws
-- type: post
-- status: published