Reputation: 792
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.
Upvotes: -4
Views: 2518
Reputation: 792
I solved the problem using the function timestamp
as written in the docs.
It didn't work before because I forgot to use the brackets to call timestamp
.
extern crate chrono;
use chrono::prelude::*;
fn main() {
let local: DateTime<Local> = Local::now();
println!("{}", local.timestamp()); // I forgot the brackets after timestamp
}
Thanks to mcarton.
Upvotes: 4
Reputation: 430290
Use Timelike::second
:
extern crate chrono;
use chrono::prelude::*;
fn main() {
let local: DateTime<Local> = Local::now();
println!("{}", local.second());
}
Upvotes: 2