Skip to content

Instantly share code, notes, and snippets.

@ryochin
Last active July 2, 2024 08:15
Show Gist options
  • Save ryochin/c0ac57b0ef3a780857b3ba5c5624b1a2 to your computer and use it in GitHub Desktop.
Save ryochin/c0ac57b0ef3a780857b3ba5c5624b1a2 to your computer and use it in GitHub Desktop.
Elixir: 日時のタプルをメール日時形式でフォーマットする
@doc """
日時のタプルをメール日時形式でフォーマットする
### Example
```
iex> {{2021, 4, 3}, {9, 46, 58}} |> datetime_to_str
"Sat, 03 Apr 2021 09:46:58 +0900"
```
"""
@spec datetime_to_str({{integer, pos_integer, pos_integer}, {non_neg_integer, non_neg_integer, non_neg_integer}}) ::
String.t()
def datetime_to_str({{year, month, day}, {hour, min, sec}}) do
Timex.to_datetime({{year, month, day}, {hour, min, sec}}, :local)
|> Timex.format!("{RFC1123}")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment