#date #formatter #implemented #third-party #formatting

bin+lib date-formatter

A date formatter crate implemented without any third-party dependencies

1 unstable release

new 0.2.0 Jan 10, 2025
0.1.0 Dec 29, 2024
0.0.1 Dec 29, 2024

#179 in Date and time

Download history 134/week @ 2024-12-25 28/week @ 2025-01-01 162/week @ 2025-01-08

324 downloads per month

MIT license

9KB
139 lines

date-formatter

Crates.io Docs.rs

A simple and lightweight date formatter crate for Rust. This crate provides functions for formatting, parsing, and performing calculations on dates.

Features

  • No dependencies: This crate is implemented using only the Rust standard library, so it has no external dependencies.
  • Easy to use: The API is simple and straightforward, making it easy to get started.
  • Lightweight: The crate is small and has minimal overhead.

Usage

Add the following to your Cargo.toml file:

[dependencies]
date-formatter = "0.1.0"  # Replace with the latest version

Then, you can use the crate in your code:

use date_formatter::{format_date, parse_date, days_between};
use std::time::SystemTime;

fn main() {
    let now = SystemTime::now();
    let formatted_date = format_date(now, "%Y-%m-%d");
    println!("Today is: {}", formatted_date);

    let parsed_date = parse_date("2024-12-29").unwrap();
    println!("Parsed date: {:?}", parsed_date);

    let yesterday = now - std::time::Duration::from_secs(86400);
    let days = days_between(now, yesterday);
    println!("Days between now and yesterday: {}", days);
}

Supported Formatting Symbols

  • %Y: Year, e.g., "2024"
  • %m: Month, e.g., "12"
  • %d: Day, e.g., "29"

Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request.

License

This crate is licensed under the MIT License.

No runtime deps