Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ISO Date String to DD/MM/YYYY
- def date_to_dd_mm_yyyy(iso_date) do
- {_, date} = Date.from_iso8601(iso_date)
- {year, month, day} = Date.to_erl(date)
- Integer.to_string(day) <> "/" <> Integer.to_string(month) <> "/" <> Integer.to_string(year)
- end
- # ISO Time String to 12 hour time
- def time_to_12hour(iso_time) do
- {:ok, new_time} = Time.from_iso8601(iso_time)
- {hour, minute, _second} = Time.to_erl(new_time)
- minute_string =
- cond do
- minute < 10 ->
- "0" <> Integer.to_string(minute)
- true ->
- Integer.to_string(minute)
- end
- hour_string =
- cond do
- hour === 0 ->
- "12"
- hour > 12 ->
- Integer.to_string(hour - 12)
- hour <= 12 ->
- Integer.to_string(hour)
- end
- meridiem =
- cond do
- hour >= 12 ->
- "pm"
- hour < 12 ->
- "am"
- end
- hour_string <> ":" <> minute_string <> meridiem
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement