Last active
July 2, 2024 08:15
-
-
Save ryochin/c0ac57b0ef3a780857b3ba5c5624b1a2 to your computer and use it in GitHub Desktop.
Elixir: 日時のタプルをメール日時形式でフォーマットする
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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