Cldr.DateTime.Formatter.year
year, go back to Cldr.DateTime.Formatter module for more information.
Specs
year(Calendar.date(), integer(), Keyword.t()) :: String.t() | {:error, String.t()}
Returns the year (format symbol y) of a date
as an integer. The y format returns the year
as a simple integer in string format.
The format yy is a special case which requests just
the two low-order digits of the year, zero-padded
as necessary. For most use cases, y or yy should
be adequate.
Arguments
dateis aDatestruct or any map that contains at least the keys:monthand:calendarnin an integer between 1 and 5 that determines the format of the yearlocaleis any valid locale name returned byCldr.known_locale_names/0or aCldr.LanguageTagstruct. The default isCldr.get_locale/0optionsis aKeywordlist of options. There are no options used inyear/4
Format Symbol
The representation of the quarter is made in accordance with the following table:
| Symbol | Example | Cldr Format |
|---|---|---|
| y | 7 | Minimum necessary digits |
| yy | "17" | Least significant 2 digits |
| yyy | "017", "2017" | Padded to at least 3 digits |
| yyyy | "2017" | Padded to at least 4 digits |
| yyyyy | "02017" | Padded to at least 5 digits |
In most cases the length of the y field specifies
the minimum number of digits to display, zero-padded
as necessary; more digits will be displayed if needed
to show the full year.
Examples
iex> Cldr.DateTime.Formatter.year %{year: 2017, calendar: Calendar.ISO}, 1
2017
iex> Cldr.DateTime.Formatter.year %{year: 2017, calendar: Calendar.ISO}, 2
"17"
iex> Cldr.DateTime.Formatter.year %{year: 2017, calendar: Calendar.ISO}, 3
"2017"
iex> Cldr.DateTime.Formatter.year %{year: 2017, calendar: Calendar.ISO}, 4
"2017"
iex> Cldr.DateTime.Formatter.year %{year: 2017, calendar: Calendar.ISO}, 5
"02017"
Specs
year(Calendar.date(), integer(), locale(), Cldr.backend(), Keyword.t()) :: String.t() | {:error, String.t()}