如何以跨平台的方式从人类可读的日期格式中获取 SystemTime? (锈)

How do I get a SystemTime from a human-readable date format in a cross-platform way? (Rust)

我如何将人类可读时间(以任何格式,例如 Tue, 1 Jul 2003 10:52:37 +0200)转换为 SystemTime, in a cross-platform way? I know about chrono::DateTime::from_rfc2822(), but I've been searching for quite a while and I can't find a way to convert a DateTime into a SystemTime. This conversion also needs to be cross-platform, so I can't use the platform-specific epochs (such as UNIX_EPOCH)。

有人对如何执行此操作有任何建议或想法吗?

DateTime<Tz>SystemTime有一个conversion available,所以你只需要调用.into():

let system_time: SystemTime = DateTime::parse_from_rfc2822("Tue, 1 Jul 2003 10:52:37 +0200").unwrap().into();

Playground