0

该文档没有说明有关此主题的任何内容。我需要把它转换成Date<Tz>? 即使这样,也没有从中获取年份组件的功能。

let current_date = chrono::Utc::now();
let year = current_date.year();  //this is not working, it should output the current year with i32/usize type
let month = current_date.month();
let date = current_date.date();
no method named `month` found for struct `chrono::DateTime<chrono::Utc>` in the current scope
4

1 回答 1

1

你需要DateLiketrait 并使用它的方法。检索Date要对其进行操作的组件:

use chrono::Datelike;
use chrono; // 0.4.19

fn main() {
    let current_date = chrono::Utc::now().date();
    println!("{}", current_date.year());
}

操场

于 2021-05-11T14:02:48.943 回答