2018-12-02 13:38:33 +00:00
# chrono-locale
2023-08-23 14:20:02 +01:00
This crate allows to format [chrono ](https://github.com/chronotope/chrono ) dates with localized months and week days. Backwards comptible fork of [Alex-PK/chrono-locale ](https://github.com/Alex-PK/chrono-locale ), now works with the latest version of chrono.
2018-12-14 08:35:56 +00:00
## Usage
2023-09-13 14:32:04 +01:00
Include the dependency in `Cargo.toml` :
2018-12-14 08:35:56 +00:00
2023-08-23 14:20:02 +01:00
```toml
2018-12-14 08:35:56 +00:00
[dependencies]
2023-08-23 14:20:02 +01:00
chrono = "0.4.56"
2023-09-06 08:39:16 +01:00
chrono_lc = "0.1.3"
2018-12-14 08:35:56 +00:00
```
2023-09-13 14:32:04 +01:00
Import the required modules into `lib.rs` or `main.rs` :
2018-12-14 08:35:56 +00:00
2023-08-23 14:44:38 +01:00
```rs
2018-12-14 08:35:56 +00:00
use chrono::prelude::*;
2023-09-06 08:35:18 +01:00
use chrono_lc::LocaleDate;
2018-12-14 08:35:56 +00:00
```
2023-09-13 14:33:43 +01:00
> **Note**
2023-09-13 14:34:10 +01:00
> You can choose to import just parts of chrono instead of the whole prelude. Please see ['`chrono`'s documentation](https://docs.rs/chrono/).
To format a chrono `Date` or `DateTime` object, you can use the `formatl` method:
2018-12-14 08:35:56 +00:00
2023-08-23 14:44:38 +01:00
```rs
2023-08-23 14:39:11 +01:00
let dt = FixedOffset::east_opt(34200)
2023-09-06 08:35:18 +01:00
.unwrap()
.with_ymd_and_hms(2001, 7, 8, 0, 34, 59)
.unwrap()
.with_nanosecond(1_026_490_708)
.unwrap();
2023-08-23 14:39:11 +01:00
2018-12-14 08:35:56 +00:00
println!("{}", dt.formatl("%c", "fr"));
```
2023-09-13 14:33:08 +01:00
> **Warning**
> All of [chrono's formatting placeholders](https://docs.rs/chrono/latest/chrono/format/strftime/index.html) work except for `%3f`, `%6f` and `%9f` (but `%.3f`, `%.6f` and `%.9f` work normally).