I have a DateTime with me,
#DateTime<2019-11-10 13:27:00.0Z> and want to replace the time part of the DateTime struct with another time, say,
11:50:07.00+02:30. The solution I found was to convert the DateTime to string and then replace the time part using
This is how my code looks.
dt = #DateTime<2019-11-11 13:27:00.0Z> dt |> DateTime.to_string() |> String.replace(~r/[[:blank:]][[:alnum:]][[:alnum:]]:[[:alnum:]][[:alnum:]]:[[:alnum:]][[:alnum:]].[[:alnum:]]Z/, "T11:50:07.00+02:30") |> DateTime.from_iso8601()
I feel there is a better way to do this, or at least there is a better regex to do it.
Does anyone have any better logic?