-4

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.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
CFV
  • 740
  • 7
  • 26
  • 2
    The seconds from when? And have you really read the documentation? Either [`timestamp`](https://docs.rs/chrono/0.4.0/chrono/struct.DateTime.html#method.timestamp) or [`second`](https://docs.rs/chrono/0.4.0/chrono/trait.Timelike.html#tymethod.second) look like they could be your answer. – mcarton Oct 01 '17 at 11:28
  • The seconds from the current date. – CFV Oct 01 '17 at 13:59
  • Now timestamp is working! I have forgotten to use the brackets! Thank you! – CFV Oct 01 '17 at 14:03

2 Answers2

3

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.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
CFV
  • 740
  • 7
  • 26
2

Use Timelike::second:

extern crate chrono;

use chrono::prelude::*;

fn main() {
    let local: DateTime<Local> = Local::now();
    println!("{}", local.second()); 
} 
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366