I have a string of date time in utc like:
2020-12-24T23:30:00+00:00
I want this to be coverted to html encoding:
2020-12-24T23%3A30%3A00%2B00%3A00
Can it be done using urllib?
You can use urllib.parse.quote.
>>> from urllib.parse import quote
>>> quote("2020-12-24T23:30:00+00:00")
'2020-12-24T23%3A30%3A00%2B00%3A00'
You can also use quote_from_bytes which is similar quote(), but accepts a bytes object rather than a str, and does not perform string-to-bytes encoding
>>> from urllib.parse import quote_from_bytes
>>> quote_from_bytes("2020-12-24T23:30:00+00:00".encode("utf-8"))
'2020-12-24T23%3A30%3A00%2B00%3A00'