[英]How can I use the Chrono library to get seconds?
I can get the date, the hours, minutes, seconds and nanoseconds in the date format, but I can't get seconds as a floating point or integer number.我可以获取日期格式的日期、小时、分钟、秒和纳秒,但我不能将秒作为浮点数或整数。
extern crate chrono;
use chrono::prelude::*;
fn main() {
let local: DateTime<Local> = Local::now();
println!("{}", local);
}
I have already read the docs.我已经阅读了文档。
Use Timelike::second
:使用
Timelike::second
:
extern crate chrono;
use chrono::prelude::*;
fn main() {
let local: DateTime<Local> = Local::now();
println!("{}", local.second());
}
I solved the problem using the function timestamp
as written in the docs.我使用文档中写的函数
timestamp
解决了这个问题。 It didn't work before because I forgot to use the brackets to call timestamp
.之前它不起作用,因为我忘记使用括号来调用
timestamp
。
extern crate chrono;
use chrono::prelude::*;
fn main() {
let local: DateTime<Local> = Local::now();
println!("{}", local.timestamp()); // I forgot the brackets after timestamp
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.