【问题标题】:How to localize chrono days?如何本地化计时日?
【发布时间】:2021-10-04 08:38:00
【问题描述】:

我有一个代码https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=cde949e0a59445ee9beb01964a3ab903

use chrono::Datelike;
use chrono::Duration;
use chrono::Local;

fn main() {
    let now = Local::now();
    println!("######################################");
    for day in 0..31 {
        println!(
            "{}",
            (now + Duration::days(7 - now.weekday().num_days_from_monday() as i64 + day))
                .format("%Y-%m-%d %A")
        );
        println!("\ntest\n\n########################");
    }
}

问:我需要在哪里显示工作日例如:“HU”语言而不是英语“Monday, Tuesday”等。

我已经尝试过基于https://docs.rs/chrono/0.4.19/chrono/ ", Locale::hu_HU)" 但到目前为止总是失败,你能帮忙吗?

【问题讨论】:

    标签: rust chrono


    【解决方案1】:

    我认为您需要 unstable-locales 功能。 format_localized的用法见here

    【讨论】:

    • 我试过了,谢谢! play.rust-lang.org/… 到目前为止它给出了 4 |使用 chrono::unstable-locales; | ^ 预期 ::;as 之一
    • @jim7475 您是否将chrono { version = "0.4", features = ["unstable-locales"] 放入您的Cargo.toml 中?我认为这是需要的,而不是 main.rs 中的 use chrono::unstable-locales;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-18
    • 2011-11-17
    • 2020-11-15
    • 2018-07-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多