Logo

Programming-Idioms

  • Elixir
  • Rust
  • Ada

Idiom #99 Format date YYYY-MM-DD

Assign to the string x the value of the fields (year, month, day) of the date d, in format YYYY-MM-DD.

with Ada.Calendar.Formatting;
X : constant String :=
    Ada.Calendar.Formatting.Image (D) (1 .. 10);

The Image function returns time as well therefore the slice.
x = Date.to_iso8601(d)
extern crate chrono;
use chrono::prelude::*;
Utc::today().format("%Y-%m-%d")
use time::macros::format_description;
let format = format_description!("[year]-[month]-[day]");
let x = d.format(&format).expect("Failed to format the date");

time crate is better maintained.
(def x (.format (java.text.SimpleDateFormat. "yyyy-MM-dd") d))

You need to add "." after both Java calls in order to make each of them an instantiation. Otherwise you call the class as a function and it errors out.

New implementation...