Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Go

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.

import "time"
x := d.Format("2006-01-02")

d has type time.Time.

January 2, 2006 is the "reference date" used for formatting.
with Ada.Calendar.Formatting;
X : constant String :=
    Ada.Calendar.Formatting.Image (D) (1 .. 10);

The Image function returns time as well therefore the slice.

New implementation...