Date to UNIX

    0

    0

    Giovanny Gongora

    Codiga's Rust Recipes

    to UNIX timestamps and vice versa

    use chrono::{NaiveDate, NaiveDateTime};
    
    fn main() {
      let date_time: NaiveDateTime = NaiveDate::from_ymd(2017, 11, 12).and_hms(17, 33, 44);
      println!(
        "Number of seconds between 1970-01-01 00:00:00 and {} is {}.",
        date_time, date_time.timestamp());
      let date_time_after_a_billion_seconds = NaiveDateTime::from_timestamp(1_000_000_000, 0);
      println!(
        "Date after a billion seconds since 1970-01-01 00:00:00 was {}.",
        date_time_after_a_billion_seconds);
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.