我有一系列utc的日期时间,比如:
2020-12-24T23:30:00+00:00
我希望将其转换为html编码:
2020-12-24T23%3A30%3A00%2B00%3A00
可以使用urllib完成吗?
你可以用 urllib.parse.quote .
urllib.parse.quote
>>> from urllib.parse import quote >>> quote("2020-12-24T23:30:00+00:00") '2020-12-24T23%3A30%3A00%2B00%3A00'
你也可以使用 quote_from_bytes 这是相似的 quote() ,但接受字节对象而不是 str ,并且不执行字符串到字节的编码
quote_from_bytes
quote()
str
>>> 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'